UISegmentControl Customisation - ios

I want to customise UISegmentControl according to link of the screenshot(Shows is selected and News is unselected) given below:
UISegmentControl Customisation
Segment with Title and Image
Borderless segments
Tap event even if Segment(Shows) is selected - I want to perform some action if user tap on selected segment

[SegmentedControlName setImage:[UIImage imageNamed:#"path"] forSegmentAtIndex:0];
For selected event you can use same thing when it also on the touched state.
Only you need to change is the path of the image

I ended up using the following library. It fulfilled my all the requirements.
PPiFlatSegmentedControl

Related

create custom segmentControl

I'm trying to create a rather custom segmentControl. What is the easiest way to create such below. with just text and a border line the selected?
You can create buttons and give tag to each of them,which will identify which button has been selected.Whenever a button is marked as selected change the state to .selected with its image.
Choice -1
ya just created 4 buttons and create the one common method , inside the method assign the tag for each button for identify which button is selected , on that selected button change the TextColor and use use Underline,else button are another color
Choice -2
ya just created 4 buttons and create the one common method , inside the method assign the tag for each button for identify which button is selected , on that selected button change the Image in UIControlStateNormal else no selection Button use normal Text or another Image
You can make fastens and offer tag to each of them,which will recognize which catch has been selected. Whenever a catch is set apart as chosen change the state to .selected with its image.

UIButton Image Not Changing With Interface Builder Settings (Selected & Disabled)

I am trying to set the toggle state of a UIButton through the interface builder. I have done it successfully using code, but I need to get it working through the interface builder.
Im not sure what the issue is but for selected I set its image to 'flashOn' and for disabled I set it to 'flashOff'
When I hold down the image, it shows the 2nd image, but pressing the image does not toggle between these two images.
Im certain it's super simple so if you can suggest what I am missing I would appreciate it
A button's selected and disabled states need to be set in code.
Can you show your implementation for when you got desired results through code? I think, from what I can piece together from your question, that you have mixed up the states of the button.
Default - images will display for this button in any state unless another is specified explicitely
Disabled - image will display when button is disabled. (button will not switch from this state through user interaction as it is disabled)
Selected - image will display when the button is selected, which as far as I know is only when you set the button as selected through code.
Highlighted - image will display when you press and hold down on the button

UIButton selected content only when touched

Is it possible to see the selected state content of an UIButton only when I'm touching it?
When you're touching a button, the button is highlighted. Call setTitle:forState: to give the button the normal title (UIControlStateNormal), and call setTitle:forState: to give it the highlighted title (UIControlStateHighlighted). Now you'll see one title normally and the other title when you touch the button. The same thing for the other button features, like setImage:forState:.

Deleselect uisegmentedcontrol selection after clicking on a save button

I'm using a 3 button UISegmented control for a choice selection. I also have a save button that retrieves the chosen control.
When the save button is clicked I want to have to UISegmentedcontrol cleared (ie the previous selected button unselected). I'm not looking for the setMomentary as I want the selection to stick but also be able to unselect it later.
[myUISegmentedControl setSelectedSegmentIndex:UISegmentedControlNoSegment];
myUISegmentedControl.selectedSegmentIndex = -1; //turn off the current selection
With Swift 4 and iOS 11, the Apple documentation states for selectedSegmentIndex:
The default value is UISegmentedControlNoSegment (no segment selected) until the user touches a segment. Set this property to -1 to turn off the current selection.
Therefore you can use one of the two following implementations in order to remove the selection of your UISegmentedControl instance:
mySegmentedControl.selectedSegmentIndex = -1
mySegmentedControl.selectedSegmentIndex = UISegmentedControlNoSegment

How to deselect selected text in an iPad application

I have a custom menu item (UIMenuItem) attached to a UIWebView. When the user selects my custom menu item after selecting some text in the web view, I want to "deslect" the current text selection. The problem is that the edit menu will pop up again when I show a modal form for some reason, I think because there is still a selected (highlighted) text range. I want to programmatically "unselect" the selected text in my custom menu item handler, after I've captured the selected range.
Use UIView's userInteractionEnabled property. Just disable user interaction and enable it back.
Like this:
myWebView.userInteractionEnabled = NO;
myWebView.userInteractionEnabled = YES;
A cleaner solution:
Swift
webView.endEditing(true)
Objective-C
[webView endEditing:YES]

Resources