iOS base Control Uisegmentedcontrol

Source: Internet
Author: User

  ***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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.