FAQ Database Discussion Community


Apply auto-layout to UISegmentedControl

ios,objective-c,autolayout,uisegmentedcontrol
I set custom widths for segments in UISegmentedControl. Because of that, the SegmentedControl doesn't use auto-layout. (In the storyboard, I applied a constraint on all 4 sides of the SegmentedControl.) Here is my code: CGFloat segmentWidth = self.segment.frame.size.width; [self.segment insertSegmentWithTitle:@"titleName" atIndex:2 animated:NO]; [self.segment setWidth:segmentWidth / 6 forSegmentAtIndex:1]; [self.segment setWidth:segmentWidth /...

Add segments from a UISegmentedControl to an NSArray

ios,objective-c,nsarray,uisegmentedcontrol,for-in-loop
I'm trying to add 2 segments to an array, then loop through its subviews. Here is my code: NSArray *myArray = [[NSArray alloc] initWithObjects:[self.segment.subviews objectAtIndex:0], [self.dataSegmentedControl.subviews objectAtIndex:1], nil]; for (id innerView in myArray) // I tried "myArray.subviews" but it didn't let me do ".subviews" { if ([innerView isKindOfClass:[UILabel class]]) {...

Adding Image And title both to UIsegmentControl IOS

ios,uiimage,title,uisegmentedcontrol
Is there a way so that you can set both image and title of UISegmentControl simultaneously, so that image appear next to the title , just like image appear next to title in UIButton. I am trying but if I set image of Selected segment of UISegmentControl then title disappears...

UISegmentedControl and localized strings

ios,objective-c,localization,uisegmentedcontrol
I have a UISegmentedControl with 3 segments. The English strings fit perfectly, but Spanish strings are slightly longer and don't. What is the correct procedure to manipulate font size dynamically for the string to fit the size of the segment? Is there something similar to the minimumFontScale property for UILabel?...

SegmentedControl changes position when run on simulator

ios,objective-c,uisegmentedcontrol,nslayoutconstraint
I have a UISegmentedControl, and I'm trying to set the widths of each segment. The code below shouldn't change anything, but it does. Here is the code: viewDidApear NSLog(@"%f", self.segment.frame.size.width); // 369 CGFloat segmentWidth = self.segment.frame.size.width; NSUInteger firstAndLastSegmentWidth = [self.segment widthForSegmentAtIndex:0] + [self.segment widthForSegmentAtIndex:4]; [self.segment setWidth:(segmentWidth - firstAndLastSegmentWidth) / 3...

Is this iOS app using segmented control?

ios,objective-c,iphone,swift,uisegmentedcontrol
In this photo (AirBnB iOS app), where it saids Upcoming and Previous, what do you guys think how this is implemented? Do you guys think this is developed using segmented control or two different buttons reversing (on/off, off/on) each other? Is there an easy way(preferably using Swift) or a library...

how to determine which segmented control is selected outside of sender func in swift

swift,uisegmentedcontrol
Please forgive new to swift-ness. I'm creating a BMI Calculator app. The app allows the user to select Imperial or Metric using a segmented control. Based on the segmented control, I change the placeholder text. Upon the 'Calculate' button, I call an extension to do the calculation. My question is:...

Setting a PFObject Value with Segmented Control

xcode,parse.com,uisegmentedcontrol
Real simply - I'm trying to create a group sharing app that allows users to create a public or private group. I have create a "CreateTableViewController" which saves an image, group name, and comments as a PFObject within Parse. This all works fine. What I want to do however, is...

How to change the font size of a single index for UISegmentedControl?

ios,objective-c,cocoa-touch,uisegmentedcontrol
The way to change the font size for a UISegmentedControl would be the following: UIFont *font = [UIFont systemFontOfSize:13.0f]; NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:UITextAttributeFont]; [self.segment setTitleTextAttributes:attributes forState:UIControlStateNormal]; How can I change the font size for a single index in a UISegmentedControl? Or even better, if the text doesn't fit...

Container views with segmented control in swift

ios,iphone,swift,uisegmentedcontrol,uicontainerview
I have a segmented control with three segments. "Cattle", "Sheep" and "Goats". In Sheep and Goats there is another segmented control "RFID" and "Mobs" I have used three container views on a parent viewController, a cattleView, sheepGoatMob view and a sheepGoatRFID view which have UITableViewControllers CattleTableViewController, SheepGoatMobTableViewController and SheepGoatRfidTableViewController. The...

Swift handle action on segmented control

swift,uisegmentedcontrol
I have a HMSegmentedControl with 4 segments. When it is selected, it should pop up view. And when the pop up dismissed, and trying to click on same segment index it should again show the pop up. By using following does not have any action on click of same segment...

UISegmentedContol change background color without changing image tint color

ios,objective-c,uisegmentedcontrol
I have a UISegmentedContol with images inside each segment. In the storyboard I set the background color and the tint color of the image to white. Now when one segment is selected, I am trying to change the background color only and keep the image tint to white (the same...

How to display a popover when user touches and holds a segment in segmented control (iOS)

ios,uipopovercontroller,uisegmentedcontrol
I need to display a popover with additional options when a user touches (and holds) a segment in UISegmentedControl. How do I: detect the hold "gesture" on the segmented control. Display the popover with additional options on top of the selected segment Thanks! note a related question is:iPad popover -...

Image in UISegmentedControl is blue?

xcode,uisegmentedcontrol
I want to put an image into the UISegmentedControl item but my image is blue, not show normal ? This is my code : NSArray *segments = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"iphone1.png"], @"iPad", @"iPod", @"iMac", nil]; self.mySegmentedControl = [[UISegmentedControl alloc] initWithItems:segments]; CGRect segmentedFrame = self.mySegmentedControl.frame; segmentedFrame.size.height = 64.0f; segmentedFrame.size.width =...

UICollectionView adding action in Header (Swift)

swift,uicollectionview,uisegmentedcontrol
I have a collectionView and a header for that collection view. I've added a UISegmentControl in my header and now I'm trying to pass the selectedSegmentIndex value to main collectionView, So i'm trying to addTarget for that segment in my UICollectionViewController but its not returning anything, here is my code...

Is it possible to use size classes to adjust the text size for UISegmentedControl objects?

ios,uisegmentedcontrol,size-classes
My app doesn't look good on large screens. On my main screen, I use a segmented control and on an iPad (Mini), it looks unprofessional, because the text size doesn't scale up in these segmented controls. The segmented control itself is easy enough to enlarge by setting constraints tying it...

How to Set tint color of text only of selected segment using Swift?

ios,swift,uisegmentedcontrol
I have used following code to set background of UISegmentedControl. homeSegment.setDividerImage(UIImage(named: "seperator.png"), forLeftSegmentState: UIControlState.Normal, rightSegmentState: UIControlState.Normal, barMetrics: UIBarMetrics.Default) homeSegment.setBackgroundImage(UIImage(named: "squareSegment.png"), forState: UIControlState.Selected, barMetrics: UIBarMetrics.Default) homeSegment.setBackgroundImage(UIImage(named: "squareSegment.png"), forState: UIControlState.Normal, barMetrics: UIBarMetrics.Default) How can I...

Changing datasource of UITableView using a UISegmentedControl (Like Twitter does)

ios,objective-c,iphone,uitableview,uisegmentedcontrol
I am trying to create a Table View in which the data source can be changed depending on which Index is selected on the UISegmentedControl. I will post what I have. It doesnt seem to be working! I want to do it like Twitter does on their profile page with...

change the back ground color of segmented control buttons

ios,xcode,uisegmentedcontrol,uicolor
friends, I am able to change the size of segments in segmented control but i need to change the background color of the segments to orange color any detailed view will be helpful ...

Make 2 segments the size of 1 in UISegmentedControl

ios,objective-c,uisegmentedcontrol
I have a UISegmentedControl with 3 segments created in the storyboard. I want to programmatically add another segment, and make the middle 2 segments the size of 1 segment. Here is an image to illustrate: In storyboard: What I want to achieve programmatically: This is what I tried: CGFloat segmentWidth...

Swift Segment Control how to select more than one segment

swift,select,uisegmentedcontrol
I have a Segment Control in my app, I want to user to be able to click multiple of the segments. I googled and could not find any about this and there was no checkbox in Xcode for something like 'Allow multiple selection'. I found that in objective-c you weren't...

UIToolbar with UISegmentedControl AutoLayout (/full width)

ios,objective-c,autolayout,uisegmentedcontrol,uitoolbar
I have a UIViewController with a UIToolBar below the UINavigationBar and a UITableView below that. The only UIBarButtonItem on my UIToolBar is a UISegmentedControl as in the screenshot below: However, how do I get the UISegmentedControl/UIBarButtonItem to stretch to fill the UIToolBar like in the App Store app? Keep in...

switching views between views in ios using segmented control

ios,xcode4.2,uisegmentedcontrol,segmentedcontrol
friends, I need to switch between four to five views off different headers There are four views Example Settings Connections Open trades close trades These are the headers I want to navigate between four pages where i click For example I want to switch to settings view when i click...

UISegmentedControl tintColor

ios,cocoa-touch,ios8,uisegmentedcontrol
I'm having problems getting UISegmentedControl to show the desired tint color. // AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // need red tint color in other views of the app [[UIView appearance] setTintColor:[UIColor redColor]]; return YES; } // ViewController - (void)viewDidLoad { [super viewDidLoad]; NSArray *items = @[@"Item 1", @"Item...

UITableView sort with NSSortDescriptor and UISegmentedControl doesn’t work

objective-c,uitableview,uisegmentedcontrol,nssortdescriptor
I want to sort my tableview by using a segmented control and sort it by a value from my datacore. According to Apple documentation my code below should work, but it doesn’t do anything. Can anyone tell me what I am doing wrong? - (void)viewDidLoad { [super viewDidLoad]; UISegmentedControl *statFilter...

iOS Swift - Change UIPageViewController page using UISegmentedControl

ios,swift,uisegmentedcontrol,uipageviewcontroller
I finnaly synchronized my segmentedController to the UIPageViewController in this way: when I swipe between pages, the segmented controller changes it's segment index. I want to know how to do the reverse too, when segmentedController's segment is tapped, to change the pageViewController page by segmentedController index. Here is my code:...

Swift Repeat Interval

uisegmentedcontrol,intervals
I have an app I'm working on with a UISegmentedControl to allow the user to select a repeat interval for the notification they are creating. They also pick the date and time to start, by selecting it on the UIDatePicker. //Variables for Repeat (SegmentedControl) var hourly = true var daily...