// Create the control (he is also transparent) Uisegmentedcontrol *seg = [[Uisegmentedcontrol alloc] initwithitems:@[@ "1"@ " 1 "@"1",@"1"];
//typedef ns_enum (Nsinteger, Uisegmentedcontrolstyle) {//Uisegmentedcontrolstyleplain,//Large Plain//uisegmentedcontrolstylebordered,//large bordered//Uisegmentedcontrolstylebar,//small Button/nav bar style. Tintable//uisegmentedcontrolstylebezeled,//DEPRECATED. don't use the This style.//} ns_deprecated_ios (2_0, 7_0, "the Segmentedcontrolstyle property no longer have any effect") __tvos_prohibited;////Enum {//uisegmentedcontrolnosegment =-1//segment index for no selected segment//};////typedef ns_enum (Nsinteger, uisegmentedcontrolsegment) {//uisegmentedcontrolsegmentany = 0,//uisegmentedcontrolsegmentleft = 1,//the capped, leftmost segment. Only applies when numsegments > 1.//Uisegmentedcontrolsegmentcenter = 2,//Any segment between the left and rightmost segments. Only applies when numsegments > 2.//uisegmentedcontrolsegmentright = 3,//The capped,rightmost segment. Only applies when numsegments > 1.//Uisegmentedcontrolsegmentalone = 4,//the standalone segment, capped on both ends. only applies when numsegments = 1.//};// @classUIImage, Uicolor;////Ns_class_available_ios (2_0) @interface Uisegmentedcontrol:uicontrol <NSCoding>//-(Instancetype) Initwithitems: (Nullable Nsarray *) items;//items can be nsstrings or uiimages. Control are automatically sized to fit content//@property (nonatomic) uisegmentedcontrolstyle Segmentedcontrolstyle Ns_deprecated_ios (2_0, 7_0,"The Segmentedcontrolstyle property no longer have any effect") __tvos_prohibited;//set whether to remain selected://Note: If set to Yes, click Finish will not remain selected, default to No@property (nonatomic,getter=ismomentary) BOOL momentary;//If set, then we don ' t keep showing selected state after tracking ends. Default is NO//get the number of tags: (read only)@property (Nonatomic,ReadOnly) Nsuinteger numberofsegments;//////For segments whose width value are 0, setting this property to YES attempts to adjust segment widths based on their Content widths. Default is NO.//sets whether the label width is adaptive with the content://Note: If set to No, all labels are the same width and are the maximum width. @property (nonatomic) BOOL apportionssegmentwidthsbycontent Ns_available_ios (5_0);////Insert text label at index position:- (void) Insertsegmentwithtitle: (Nullable NSString *) title Atindex: (Nsuinteger) segment animated: (BOOL) animated;//Insert before segment number. 0.. #segments. Value pinned//Insert Picture label at index position:- (void) Insertsegmentwithimage: (Nullable UIImage *) Image atindex: (Nsuinteger) segment animated: (BOOL) animated;//To remove the index position label:- (void) Removesegmentatindex: (Nsuinteger) segment animated: (BOOL) animated;//Remove All location Tags:- (void) removeallsegments;//Reset Title label (Specify position)- (void) Settitle: (Nullable NSString *) title Forsegmentatindex: (Nsuinteger) segment;//can only has an image or title, not both. Must be 0: #segments-1 (or ignored). Default is nil//reset the label's picture (Specify position)- (void) SetImage: (Nullable UIImage *) image forsegmentatindex: (Nsuinteger) segment;//can only has an image or title, not both. Must be 0: #segments-1 (or ignored). Default is nil//gets the text of the specified position label-(Nullable NSString *) Titleforsegmentatindex: (Nsuinteger) segment;//gets the picture of the specified position label-(Nullable UIImage *) Imageforsegmentatindex: (Nsuinteger) segment;////sets the width of the specified position label- (void) SetWidth: (cgfloat) Width Forsegmentatindex: (nsuinteger) segment;//set to 0.0 width to AutoSize. Default is 0.0//gets the width of the specified position label-(CGFloat) Widthforsegmentatindex: (Nsuinteger) segment;////set the offset of the content (picture, or text)- (void) Setcontentoffset: (cgsize) offset Forsegmentatindex: (Nsuinteger) segment;//adjust offset of image or text inside the segment. Default is (0,0)//gets the offset of the content (picture, or text)-(cgsize) Contentoffsetforsegmentatindex: (Nsuinteger) segment;////sets whether the specified location label is available- (void) setenabled: (BOOL) enabled Forsegmentatindex: (Nsuinteger) segment;//default is YES//gets whether the specified location label is available-(BOOL) Isenabledforsegmentatindex: (Nsuinteger) segment;//////ignored in momentary mode returns last segment pressed. Default is uisegmentedcontrolnosegment until a segment is P Ressed////The Uicontroleventvaluechanged action is invoked if the segment changes via a user event. Set to Uisegmentedcontro Lnosegment to turn off selection//gets the currently selected label@property (nonatomic) Nsinteger Selectedsegmentindex;//////The Tintcolor is inherited through the Superview hierarchy. See UIView for more information.//color that affects pictures and text@property (null_resettable,nonatomic,strong) Uicolor *Tintcolor;/////* If BackgroundImage is a image returned from-[uiimage resizableimagewithcapinsets:] The cap widths would be calculat Ed from that information, otherwise, the cap width'll be calculated by subtracting one from the image's width then divID ing by 2. The cap widths would also is used as the margins for text placement. To adjust the margin use the margin adjustment methods.// //in general, you should specify a value for the normal state to being used by other States which don ' t has a custom valu E set.// //Similarly, when a property was dependent on the bar metrics, being sure to specify a value for Uibarmetricsdefault.//in the case of the segmented control, appearance properties for Uibarmetricscompact is only respected for segmented Controls in the smaller navigation and toolbars.// *///set the background pattern for a segment in a specific state- (void) SetBackgroundImage: (Nullable UIImage *) backgroundimage forstate: (uicontrolstate) State barmetrics: (uibarmetrics) barmetrics Ns_available_ios (5_0) UI_ Appearance_selector;//Note: Uibarmetrics is an enumeration, as follows: (Defaulf style will fill the background)//typedef ns_enum (Nsinteger, uibarmetrics) {//Uibarmetricsdefault,//Uibarmetricscompact,//uibarmetricsdefaultprompt = 101,//applicable bars with the prompt property, such as Uinavigationbar and Uisearchbar//Uibarmetricscompactprompt,// //Uibarmetricslandscapephone Ns_enum_deprecated_ios (5_0, 8_0, "use Uibarmetricscompact instead") = Uibarmetricscomp Act,//uibarmetricslandscapephoneprompt Ns_enum_deprecated_ios (7_0, 8_0, "use uibarmetricscompactprompt") = Uibarmetricscompactprompt,//};//Get background pattern-(Nullable UIImage *) Backgroundimageforstate: (uicontrolstate) State barmetrics: (uibarmetrics) barmetrics Ns_available_ios (5_0) UI_ Appearance_selector;/////* To customize the segmented control appearance you'll need to provide divider images to go between both unselected s Egments (Leftsegmentstate:uicontrolstatenormal rightsegmentstate:uicontrolstatenormal), selected on the left and Unselected on the right (leftsegmentstate:uicontrolstateselected rightsegmentstate:uicontrolstatenormal), and Unselected on the left and selected in the right (Leftsegmentstate:uicontrolstatenormal rightsegmentstate: uicontrolstateselected).// *///set the pattern of dividing lines between labels- (void) Setdividerimage: (Nullable UIImage *) dividerimage forleftsegmentstate: (uicontrolstate) leftstate rightsegmentstate: (uicontrolstate) rightState Barmetrics: (uibarmetrics) barmetrics Ns_available_ios (5_0) ui_appearance_selector;//get the pattern of dividing lines between labels-(Nullable UIImage *) Dividerimageforleftsegmentstate: (uicontrolstate) leftstate rightsegmentstate: (uicontrolstate) rightState Barmetrics: (uibarmetrics) barmetrics Ns_available_ios (5_0) ui_appearance_selector;/////* Specify the font, text color, and shadow properties for the title in the text attributes dictionary, using T He keys found in NSAttributedString.h.// *///To set the label caption by attribute the string property dictionary- (void) Settitletextattributes: (Nullable nsdictionary *) Attributes Forstate: (uicontrolstate) state Ns_available_ios (5_0) ui_appearance_selector;//Get Attribute string property dictionary-(Nullable Nsdictionary *) Titletextattributesforstate: (uicontrolstate) state Ns_available_ios (5_0) ui_appearance_selector;/////* For adjusting the position of a title or image within the given segment of a segmented control.// *///set the offset of the label content yourself//Note: The Uioffset is an offset, the structure of two floating-point numbers, respectively, the level and the vertical amount; The Uisegmentedcontrolsegment type parameter is an enumeration, as follows//typedef ns_enum (Nsinteger, uisegmentedcontrolsegment) {//uisegmentedcontrolsegmentany = 0,//all labels are affected//uisegmentedcontrolsegmentleft = 1,//only the left part is affected//Uisegmentedcontrolsegmentcenter = 2,//only the middle ones are affected .//uisegmentedcontrolsegmentright = 3,//only the right part is affected .//Uisegmentedcontrolsegmentalone = 4,//take effect when there is only one label//};- (void) Setcontentpositionadjustment: (uioffset) Adjustment forsegmenttype: (uisegmentedcontrolsegment) Leftcenterrightoralone barmetrics: (uibarmetrics) barmetrics Ns_available_ios (5_0) ui_appearance_selector;//Gets the custom offset-(Uioffset) Contentpositionadjustmentforsegmenttype: (uisegmentedcontrolsegment) Leftcenterrightoralone Barmetrics: (uibarmetrics) barmetrics Ns_available_ios (5_0) ui_appearance_selector;////Add a Click event//[_seg addtarget:self Action: @selector (Segclick:) forcontrolevents:uicontroleventvaluechanged];- (void) Segclick: (Uisegmentedcontrol *) seg{// //NSLog (@ "-%ld", seg.selectedsegmentindex);//}
Article Three-Uisegmentedcontrol