iOS Practice 02

Source: Internet
Author: User

The next day, on a day of lessons, software testing, data mining, probability theory, the evening has time to beat the drum program.

Today is just a little bit easier to do. Think of their own thinking can not be written, only simple to write a process, not like the first time to write this, less a lot of thinking.

1. Perfect Tabbar message reminder, custom Reminder small icon. Use KVO to dynamically change the display value of the badge (code: 006), the Sina's badge picture needs to be stretched, there is a uiiamge classification of his own writing (mainly based on stretching from the center of the picture, will be written in the comments)

// Add Reminder Number button 2 Svbadgebutton *badgebtn = [[Svbadgebutton alloc] init]; 3 badgebtn.autoresizingmask = Uiviewautoresizingflexibleleftmargin |     Uiviewautoresizingflexiblebottommargin; 4 [self addsubview:badgebtn]; 5 self.badgebtn  = badgebtn;
1 //0062 //Set Item3- (void) SetItem: (Uitabbaritem *) Item4 {5_item =item;6     7     //KVO Monitoring Property changes8[Item addobserver:self Forkeypath:@"Badgevalue"Options0Context:nil];9[Item addobserver:self Forkeypath:@"title"Options0Context:nil];Ten[Item addobserver:self Forkeypath:@"Image"Options0Context:nil]; One[Item addobserver:self Forkeypath:@"SelectedImage"Options0Context:nil]; A      - [self Observevalueforkeypath:nil ofobject:nil change:nil Context:nil]; - } the  -- (void) Dealloc - { -[Self.item removeobserver:self Forkeypath:@"Badgevalue"]; +[Self.item removeobserver:self Forkeypath:@"title"]; -[Self.item removeobserver:self Forkeypath:@"Image"]; +[Self.item removeobserver:self Forkeypath:@"SelectedImage"]; A } at  - /** - * When the properties of an object are monitored, it is called -  * - * @param keypath property name - * @param object whose properties are changed in * @param change property changes -  */ to- (void) Observevalueforkeypath: (NSString *) KeyPath Ofobject: (ID)ObjectChange: (nsdictionary *) Change context: (void*) Context + { -     //Set Text the [self setTitle:self.item.title forstate:uicontrolstateselected]; * [self setTitle:self.item.title forstate:uicontrolstatenormal]; $     Panax Notoginseng     //set up a picture - [self setImage:self.item.image forstate:uicontrolstatenormal]; the [self setImage:self.item.selectedImage forstate:uicontrolstateselected]; +      A     //Set Reminder Numbers theSelf.badgeBtn.badgeValue =Self.item.badgeValue; +      -     //set the location of the reminder number $CGFloat Badgey =5; $CGFloat Badgex = self.frame.size.width-self.badgebtn.frame.size.width-Ten; -CGRect BADGEF =Self.badgeBtn.frame; -Badgef.origin.x =Badgex; theBADGEF.ORIGIN.Y =Badgey; -Self.badgeBtn.frame =BADGEF;Wuyi}

2. Improve the details of the Nav navigation bar (setting of global properties): Upper right button on the left, need to write their own button in their VC, and the whole nav theme in Nav write Good (code: 007).

1 //Code 0072 //The first time you use this class, you'll call3+ (void) Initialize4 {5     //set the navigation bar theme6 [self setupnavbar];7     //Set Button Theme8 [self setupnavbaritem];9 }Ten  One+ (void) Setupnavbar A { -     //Remove the current Tabbar -Uinavigationbar *bar =[Uinavigationbar appearance]; the     //Set caption Properties -Nsmutabledictionary *textdic =[Nsmutabledictionary dictionary]; -Textdic[nsfontattributename] = [Uifont boldsystemfontofsize: +]; -Textdic[nsforegroundcolorattributename] =[Uicolor Blackcolor]; +      - [Bar Settitletextattributes:textdic]; + } A+ (void) Setupnavbaritem at { -Uibarbuttonitem *item =[Uibarbuttonitem appearance]; -      -     //Set Text Properties -Nsmutabledictionary *textattrs =[Nsmutabledictionary dictionary]; -Textattrs[nsfontattributename] = [Uifont boldsystemfontofsize: -]; inTextattrs[nsforegroundcolorattributename] =[Uicolor Orangecolor]; - [item Settitletextattributes:textattrs forstate:uicontrolstatenormal]; to [item Settitletextattributes:textattrs forstate:uicontrolstatehighlighted]; +}

3. The middle title of the home controller needs to be customized, put a button that can be clicked on there. For the left and right buttons, because Sina for NavBarItem to provide a picture, all again for Uibarbuttonitem wrote classification.

1- (void) Viewdidload {2 [Super Viewdidload];3[self.tabbarcontroller.tabbar.items[0] Setbadgevalue:@" About"];4     //left button5Self.navigationItem.leftBarButtonItem = [Uibarbuttonitem Itemwithicon:@"Navigationbar_friendsearch_os7"Highicon:@"Navigationbar_friendsearch_highlighted_os7"target:self Action: @selector (Findfriend)];6     7     //Right Button8Self.navigationItem.rightBarButtonItem = [Uibarbuttonitem Itemwithicon:@"Navigationbar_pop_os7"Highicon:@"Navigationbar_pop_highlighted_os7"target:self Action: @selector (POP)];9     Ten     //middle Button OneSVTITLEBTN *titlebtn =[svtitlebtn Titlebutton]; A     //icons -[Titlebtn setimage:[uiimage imagenamed:@"Navigationbar_arrow_down"] forstate:uicontrolstatenormal]; -     //text the[Titlebtn Settitle:@"Sleen"Forstate:uicontrolstatenormal]; -     //Location and Size -Titlebtn.frame = CGRectMake (0,0, the, +); -     //Titlebutton.tag = Iwtitlebuttondowntag; + [titlebtn addtarget:self Action: @selector (Titleclick:) forcontrolevents:uicontroleventtouchupinside]; -Self.navigationItem.titleView =titlebtn; + } A- (void) Titleclick: (SVTITLEBTN *) titlebtn at {  -     if(Titlebtn.tag = =0 ) { -[Titlebtn setimage:[uiimage imagenamed:@"navigationbar_arrow_up"] forstate:uicontrolstatenormal]; -Titlebtn.tag =-1; -}Else { -[Titlebtn setimage:[uiimage imagenamed:@"Navigationbar_arrow_down"] forstate:uicontrolstatenormal]; inTitlebtn.tag =0; -     } to}

4. Found in the middle of the controller is a search box, but also to write their own here directly to the previous write that, think it is too easy to use (code: 008)

1 //0082- (void) Viewdidload3 {4 [Super Viewdidload];5     //Initialize6Slsearchbar *search =[Slsearchbar Searchbar];7     //Set Location8Search.frame = CGRectMake (0,0, -, -);9     //Add search BoxTenSelf.navigationItem.titleView =Search; One}

iOS Practice 02

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.