***UISegmentedControl控件是iOS中比较常用的控件,作为一个iOS手机设备屏幕,一下子放多个UIButton,显然感觉不到美观,作为一个不妥协追求卓越的乔帮主肯定不愿意,所以设计出该控件,以满足平时的需求。***
Nsarray *segmentedarray=[[nsarray alloc]initwithobjects:@ "One", @ "two", @ "three", @ "four", nil];
Creating Uisegmentedcontrol is similar to previous controls:
Segmentedcontrol=[[uisegmentedcontrol Alloc]initwithitems:segmentedarray];
Segemntedcontrol.frame=cgrectmake (80,180,250,60); control initialization and position setting
The Uisegmentedcontrol control is a control that can be customized in depth:
segmentedcontrol.selectedsegmentindex=1;//Default Check index (count is from 0)
Segmentedcontrol.tintcolor=[uicolor redcolor];//Setting the background color
segmentedcontrol.momentary=yes;//settings are restored after clicking
[Self.segmentedcontrol settitle:@ "YES" forsegmentatindex:1];//set the title of the specified index
[Self.view Addsubview:segmentedcontrol];
Set the style of the control, but tried, there is a warning, do not know whether the iOS8 is canceled or modified, to be determined!
Segmentedcontrol.segmentedcontrolstyle=uisegmentedcontrolstylebar;
Several styles:
typedef enum
{
Uisegmentedcontrolstyleplain,
Uisegmentedcontrolstylebordered,
Uisegmentedcontrolstylebar,
Uisegmentedcontrolstylebezeled
}style;
Each small paragraph is actually a small button UIButton, you can set the label, background, and listen to events
Listener events are the same as other controls:
[Segmentedcontrol addtarget:self Action: @selector (segmentedaction:) forcontrolevents:uicontroleventvaluechanged];
-(void) Segmentedaction: (Uisegmentedcontrol *) Seg
{
Nsinteger Index=seg.selectedsegmentindex;
Switch (index) {
Case 0:
NSLog (@ "%ld", (long) index);
Break
case 1: NSLog(@"%ld",(long)index); break; case 2: NSLog(@"%ld",(long)index); break; case 3: NSLog(@"%ld",(long)index); break;}
}
[Self.segmentedcontrol setimage:[uiimage imagenamed:@ "] forsegmentatindex:3];//set the picture of the specified index
Add a small segment button at the specified location:
[SegmentedControl1 insertsegmentwithtitle:@ "Add" atindex:0 Animated:yes];
Whether or not the press will automatically release:
Segmentedcontrol1.momentary = YES;
Multi-Touch Support:
Segmentedcontrol.multipletouchenabled=no;
Shows that the control is typically two cases in real-world development:
One, displayed on the normal view
[Self.view Addsubview:segmentedcontrol];
Second, the display on the navigation bar,
Self.navigationitem.titleview=segmentedcontrol;
iOS base Control Uisegmentedcontrol