Uisegmentedcontrol Related foundation of Ios:ui design

Source: Internet
Author: User
<span id="Label3"></p><p><p>Functions: <span style="color: #0000ff;">Segmented control, page switching, etc.</span> ;</p></p><p><p>  <span style="color: #0000ff;">They are often used to choose between different categories of information, or to switch between different application Screens.</span></p></p><p><p></p></p><p><p>The following are the basic properties and use of basic methods:</p></p><p><p>  <span style="color: #0000ff;">nsarray</span> *array = [nsarray <span style="color: #0000ff;">arraywithobjects</span>: @ "search", @ "music", @ "video", @ "novel", nil]; <span style="color: #ff0000;">//create an array</span></p></p><p><p>Uisegmentedcontrol *segmentedcont = [[uisegmentedcontrol alloc]initwithitems:array]; <span style="color: #ff0000;">//initialize the uisegmentedcontrol, and add an array of arrays, and generate the corresponding number of columns according to the array</span></p></p><p><p>Segmentcont.    <span style="color: #0000ff;">frame</span> = Cgrestmake (x,y,w,h); <span style="color: #ff0000;">//set Frame</span></p></p><p><p>Segmentcont<span class="s1">. <span class="s2"> <span style="color: #0000ff;">Segmentedcontrolstyle</span>  <span class="s1">= <span style="color: #0000ff;">uisegmentedcontrolstylebezeled</span><span class="s1">; <span style="color: #ff0000;">//set The style of the column</span> </span> </span> </span> </span></p></p><p><p><span class="s1"><span class="s2"><span class="s1"><span class="s1">    <span style="color: #ff0000;">Display styles in IOS<span style="color: #0000ff;">7</span> system Environment</span></span></span></span></span></p></p><p><p><span class="s1"><span class="s2"><span class="s1"><span class="s1">                       </span></span></span></span><span style="color: #0000ff;">Uisegmentedcontrolstylebar</span>;</p></p><p><p>                       <span style="color: #0000ff;">Uisegmentedcontrolstyleplain</span>;</p></p><p><p>                       <span style="color: #0000ff;">uisegmentedcontrolstylebordered</span>;</p></p><p><p>        <span style="color: #ff0000;">If you're using a simulator for the <span style="color: #0000ff;">IOS7 system</span> , you'll find that no matter which of these styles you use, <span style="color: #0000ff;">they show the same effect</span> , but on <span style="color: #0000ff;">IOS6</span> , they show a different <span style="color: #0000ff;">effect</span> . , because the small series does not have the simulator of the IOS6 system, so no, this is left to the reader to experience</span></p></p><p><p>  <span lang="EN-US" xml:lang="EN-US">Segmentedcont. <span style="color: #0000ff;">Tintcolor</span> = [uicolor redcolor];</span></p></p><p><p><span lang="EN-US" xml:lang="EN-US">    <span style="color: #ff0000;">Set its color, but this color is only for its <span lang="EN-US" xml:lang="EN-US"> <span style="color: #0000ff;">uisegmentedcontrolstylebar</span> and <span lang="EN-US" xml:lang="EN-US"> <span style="color: #0000ff;">uisegmentedcontrolstylebezeled</span> Style useful</span></span></span></span></p></p><p><p></p></p><p><p>Segmentedcont.    <span style="color: #0000ff;">Selectedsegmentindex</span> = 2; <span style="color: #ff0000;">//set Default selection index 0,1,2,3 ....</span></p></p><p><p>Segmentedcont.        <span style="color: #0000ff;">Momentary</span> = YES; <span style="color: #ff0000;">//set whether to revert to the original after clicking</span></p></p><p><p>       <span style="color: #993366;"> <span style="color: #ff6600;">personally, the following basic methods of inserting index entries are not commonly used, and it is possible to understand</span></span></p></p><p><p>[segmentedcont <span style="color: #0000ff;">settitle</span>: @ "the" <span style="color: #0000ff;">forsegmentatindex</span>: 2]; <span style="color: #ff0000;">//set The title of the specified index</span></p></p><p><p>[segmentedcont <span style="color: #0000ff;">setimage</span>: [UIImage imagenamed:@ "name.png"] <span style="color: #0000ff;">forsegmentatindex</span>: 3]; <span style="color: #ff0000;">//set A picture of the specified index, the picture needs to select the appropriate size</span></p></p><p><p>[segmentedcont <span style="color: #0000ff;">insertsegmentwithimage</span>: [UIImage imagenamed:@ "name1.png"] <span style="color: #0000ff;">atindex</span>: 2 animated:no]; <span style="color: #ff0000;">//insert an option at the specified index and set the picture</span></p></p><p><p>[segmentedcont <span style="color: #0000ff;">insertsegmentwithtitle</span>: @ "insert" <span style="color: #0000ff;">atindex</span>: 3 animated:no]; <span style="color: #ff0000;">//insert an option at the specified index and set the title</span></p></p><p><p>[segmentedcont <span style="color: #0000ff;">removesegmentatindex</span>: 0 animated:no]; <span style="color: #ff0000;">//remove options for the specified index</span></p></p><p><p>[segmentedcont <span style="color: #0000ff;">setwidth</span>: 70.0 <span style="color: #0000ff;">forsegmentatindex</span>: 2]; <span style="color: #ff0000;">//set the width of the specified index option</span></p></p><p><p>[segmentedcontrol <span style="color: #0000ff;">setcontentoffset</span>: Cgsizemake (10.0,10.0) <span style="color: #0000ff;">forsegmentatindex</span>: 3]; <span style="color: #ff0000;">//set the position of the upper left corner of the picture in the options</span></p></p><p><p>  </p></p><p><p>    <span style="color: #ff0000;">//get picture Imageforsegmentatindex for the specified index option:</span></p></p><p><p>  <span style="color: #0000ff;">uiimageview</span> *imageforsegmentatindex = [[uiimageview Alloc]initwithimage:[segmentedcont <span style="color: #0000ff;"> Imageforsegmentatindex</span>: 1];</p></p><p><p>Imageforsegmentatindex. <span style="color: #0000ff;">frame</span> = CGRectMake (x, y, w, h);</p></p><p><p>    </p></p><p><p>        <span style="color: #ff0000;">//get <span style="color: #0000ff;">Total number of options</span> segmentedcontrol.numberofsegments</span></p></p><p><p>UILabel *numberofsegments = [[UILabel alloc]initwithframe:cgrectmake (x, y, w, h)];</p></p><p><p>Numberofsegments. <span style="color: #0000ff;">text</span> = [nsstring stringwithformat:@ "%d", segmentedcont. <span style="color: #0000ff;"> numberOfSegments</span>];</p></p><p><p></p></p><p><p>      <span style="color: #ff0000;">//gets the width of the specified index option widthforsegmentatindex:</span></p></p><p><p>UILabel *widthforsegmentatindex = [[UILabel alloc]initwithframe:cgrectmake (x, y, w, h)];</p></p><p><p>Widthforsegmentatindex. <span style="color: #0000ff;">text</span> = [nsstring stringwithformat:@ "%f", [segmentedcont <span style="color: #0000ff;">widthforsegmentatindex</span>: 2]];</p></p><p><p>  </p></p><p><p>[segmentedcont <span style="color: #0000ff;">setenabled</span>: NO <span style="color: #0000ff;">forsegmentatindex</span>: 4]; <span style="color: #ff0000;">//set The specified index option is not selectable</span></p></p><p><p>BOOL <span style="color: #0000ff;">Enableflag</span> = [segmentedcont <span style="color: #0000ff;">isenabledforsegmentatindex</span>: 4]; <span style="color: #ff0000;">//determines whether the specified index option is optional</span></p></p><p><p>  </p></p><p><p>      <span style="color: #ff0000;">To add a delegate method</span></p></p><p><p>Segmentedcont <span style="color: #0000ff;">addTarget</span>: Self action:<span style="color: #ff0000;">@selector</span>(<span style="color: #0000ff;">segmentaction:</span>) forcontrolevents: <span style="color: #0000ff;"> Uicontroleventsvaluechanged</span>];</p></p><p><p></p></p><p><p>          <span style="color: #ff0000;">Examples of specific delegate methods:</span></p></p><p><p>-(void)<span style="color: #ff0000;">segmentaction</span>:(<span style="color: #0000ff;">uisegmentedcontrol *</span>) SC</p></p><p><p>{</p></p><p><p>  <span style="color: #0000ff;">Nsinteget</span>   Index = SC.<span style="color: #0000ff;">selectedsegmentindex</span>; <span style="color: #ff0000;">//get index Value</span></p></p><p><p>NSLog (@ "index:%i", Index);</p></p><p><p>  <span style="color: #0000ff;">Switch</span> (Index) { <span style="color: #ff0000;">//to determine the selected index value</span></p></p><p><p>      <span style="color: #0000ff;"></span> Case 0:</p></p><p><p>{<span style="color: #ff0000;">//response event</span> };</p></p><p><p>Break</p></p><p><p>      <span style="color: #0000ff;"></span> Case 1:</p></p><p><p>{<span style="color: #ff0000;">//response event</span> };</p></p><p><p>Break</p></p><p><p>      <span style="color: #0000ff;"></span> Case 2:</p></p><p><p>{<span style="color: #ff0000;">//response event</span> };</p></p><p><p>Break</p></p><p><p>      <span style="color: #0000ff;"></span> Case 3:</p></p><p><p>{<span style="color: #ff0000;">//response event</span> };</p></p><p><p>Break</p></p><p><p>Default</p></p><p><p>Break</p></p><p><p>}</p></p><p><p>}</p></p><p><p></p></p><p><p><span style="color: #0000ff;">(may Learn relatively shallow, if you have to add can leave a message, there are questions to discuss with you, you can contact privately: Qq790444804:hgwchihuo</span></p></p><p><p><span style="color: #0000ff;">-------i'm a happy little tail ' (*∩_∩*)</span></p></p><p><p>Uisegmentedcontrol Related foundation of Ios:ui design</p></p></span>

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.