ios-uisegmentedcontrol-Hide Border

Source: Internet
Author: User

Principle:

1. Use the Tintcolor property to set the entire uisegmentcontrol as a transparent color.

2. Set the titletextattributes in the normal state and the titletextattributes in the selected state.

#import "SecondViewController.h"#import "Masonry.h"@interfaceSecondviewcontroller () @property (nonatomic, strong) Uisegmentedcontrol*Segmentedcontrol_one;@end@implementationSecondviewcontroller#pragmaMark-Life cycle#pragmaMark Viewdidload-(void) viewdidload{[Super Viewdidload];        [Self basicsetting];    [Self addsegmentedcontrol_one]; }#pragmaMark-System Agent#pragmaMark-click Event-(void) Segmentedcontrol_one: (Uisegmentedcontrol *) sender{NSLog (@"Index:%ld",(Long) sender.selectedsegmentindex); }#pragmaMark-Implementation Method#pragmaMark Basic Settings-(void) basicsetting{Self.title=@"Hide Border";}- (void) addsegmentedcontrol_one{[Self.view AddSubview:self.segmentedControl_one]; [Self.segmentedcontrol_one mas_makeconstraints:^ (Masconstraintmaker *Make ) {Make.left.mas_equalTo (Self.view). With.offset (Ten); Make.right.mas_equalTo (Self.view). With.offset (-Ten); Make.top.mas_equalTo (Self.view). With.offset ( -); Make.height.mas_equalTo ( +); }];}#pragmaMark-setter & getter-(Uisegmentedcontrol *) segmentedcontrol_one{if(!_segmentedcontrol_one) {Nsarray* Array = @[@"First paragraph",@"second paragraph",@"Third paragraph",@"Fourth paragraph"]; Self.segmentedcontrol_one=[[Uisegmentedcontrol alloc] initwithitems:array]; //Remove the color, now the whole segment I can not see, the corresponding Click eventSelf.segmentedControl_one.tintColor =[Uicolor Clearcolor]; //under normal conditionNsdictionary * normaltextattributes = @{nsfontattributename: [Uifont systemfontofsize:16.0f],nsforegroundcolorattributename: [Uicolor Graycolor]};                [Self.segmentedcontrol_one settitletextattributes:normaltextattributes Forstate:uicontrolstatenormal]; //In the selected stateNsdictionary * selctedtextattributes = @{nsfontattributename: [Uifont boldsystemfontofsize:20.0f],nsforegroundcolorattributename: [Uicolor Redcolor]};                        [Self.segmentedcontrol_one settitletextattributes:selctedtextattributes forstate:uicontrolstateselected]; [Self.segmentedcontrol_one addtarget:self Action: @selector (segmentedcontrol_one:) forcontrolevents:uicontrolevent    ValueChanged]; }    return_segmentedcontrol_one;}@end

ios-uisegmentedcontrol-Hide Border

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.