uisegmentedcontrol

How to customize UISegmentedControl to change selected segment bottom border?

邮差的信 提交于 2021-02-08 07:32:48
问题 I want to customize UISegmentedControl like this image: 回答1: Use extension with this self.segmentController.customizeAppearance(for: 1) Call addBorder method and pass your UISegmentedControl as a parameter static func addBorder(_ uiSegmentControl: UISegmentedControl){ var upperBorder: CALayer = CALayer() upperBorder.backgroundColor = UIColor.init(red: 255.0, green:255.0, blue: 255.0, alpha: 1.0).cgColor upperBorder.frame = CGRect(x: 0, y: Int(ceil(uiSegmentControl.subviews[0].bounds.height))

SelectedTintColor of Segment Control is not rounded corner on iOS 13

China☆狼群 提交于 2021-02-06 09:25:08
问题 Rounded corner is working great on iOS 12 and below, but it's broken on iOS 13. I've created a custom Segment control class. Code: class SegmentedControl: UISegmentedControl { override func layoutSubviews() { super.layoutSubviews() layer.cornerRadius = self.bounds.size.height / 2.0 layer.borderColor = UIColor(red: 170.0/255.0, green: 170.0/255.0, blue: 170.0/255.0, alpha: 1.0).cgColor layer.borderWidth = 1.0 layer.masksToBounds = true clipsToBounds = true } } I've gone through this post - How

SelectedTintColor of Segment Control is not rounded corner on iOS 13

家住魔仙堡 提交于 2021-02-06 09:22:50
问题 Rounded corner is working great on iOS 12 and below, but it's broken on iOS 13. I've created a custom Segment control class. Code: class SegmentedControl: UISegmentedControl { override func layoutSubviews() { super.layoutSubviews() layer.cornerRadius = self.bounds.size.height / 2.0 layer.borderColor = UIColor(red: 170.0/255.0, green: 170.0/255.0, blue: 170.0/255.0, alpha: 1.0).cgColor layer.borderWidth = 1.0 layer.masksToBounds = true clipsToBounds = true } } I've gone through this post - How

iOS: Custom top segmented control works as expected only when using debugger

懵懂的女人 提交于 2021-01-28 19:02:15
问题 I'm trying to create a custom top swipe menu that has a moving resizing orange bar that denotes which tab is selected. This is an extremely common design and I'm just doing this for practice as I am new to swift. You navigate by either swiping through the bottom collectionView or you can select a tab on the top menu. The top menu is also just a collectionView and is scrollable as well. As you can see below (first gif), my problem is that when I try to go back to the first tab, whether by

detect event when tapped on already selected segment

我只是一个虾纸丫 提交于 2020-05-26 04:22:46
问题 Hi i want to get event when i touch on already selected segment. i have implemented below solution import UIKit class MARSSegmentController: UISegmentedControl { /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. override func drawRect(rect: CGRect) { // Drawing code } */ override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { let oldValue:NSInteger = self.selectedSegmentIndex super

make an uisegmentedcontrol in an uiscrollview

那年仲夏 提交于 2020-02-02 10:36:27
问题 I want to use a very large segmentedcontrol component so I had the idea to make it in a uiscrollview ..so by scrolling horizontally user can choose the appropriate item. I wrote this code: CGRect rect = [[UIScreen mainScreen] applicationFrame]; CGRect frame = CGRectMake(rect.origin.x + kLeftMargin, rect.size.height - kPaletteHeight - kTopMargin, 2*rect.size.width , kPaletteHeight); seg.frame = frame; scroll.frame = frame; scroll.contentSize = CGSizeMake(frame.size.width * 2,frame.size.height)

Change border color of UISegmentedControl

六月ゝ 毕业季﹏ 提交于 2020-02-01 10:03:20
问题 I need different border colour for both the sections.By default I am having white as border color. Can anyone help me out with this? 回答1: Extension method code for the Segment Control. This is working code with Latest Swift 3.0 [March 2017] The Extension method is created, as the extension to the native segment control. extension UISegmentedControl { func setSegmentStyle() { let segmentGrayColor = UIColor(red: 0.889415, green: 0.889436, blue:0.889424, alpha: 1.0 ) setBackgroundImage

Change border color of UISegmentedControl

两盒软妹~` 提交于 2020-02-01 09:58:08
问题 I need different border colour for both the sections.By default I am having white as border color. Can anyone help me out with this? 回答1: Extension method code for the Segment Control. This is working code with Latest Swift 3.0 [March 2017] The Extension method is created, as the extension to the native segment control. extension UISegmentedControl { func setSegmentStyle() { let segmentGrayColor = UIColor(red: 0.889415, green: 0.889436, blue:0.889424, alpha: 1.0 ) setBackgroundImage

How do I switch UIsegmentedControll programmatically?

落爺英雄遲暮 提交于 2020-01-30 18:19:27
问题 How do I switch UISegmentedControll programmatically ? 回答1: The selectedSegmentIndex property identifies the selected segment of a UISegmentedControl. Set this property to the any valid segment index, or UISegmentedControlNoSegment (-1) to turn off the current selection. // select the first segment segmented.selectedSegmentIndex = 0; // turn off the current selection segmented.selectedSegmentIndex = UISegmentedControlNoSegment; 回答2: Alternatively, after you have changed the