The development path of IOS--micro-bo skeleton build _ios

Source: Internet
Author: User
Tags prepare reserved set background uikit

Final Effect Diagram:


Beyondviewcontroller.m

BEYONDVIEWCONTROLLER.M//20_ handsome no Weibo////Created by Beyond on 14-8-3. Copyright (c) 2014 Com.beyond.
All rights reserved.
 This is the main controller, divided into two, the following is the dock bar, the above is to show the different child controller view, the child controller is best to use the navigation controller packaging, this way the controller brought the navigation bar, left button, title, right button//can not click, or click No response reasons:
 userinteractionenabled = NO; Hidden = YES Alpha <= 0.01 clearcolor, view color is transparent, can not be clicked * * #import "BeyondViewController.h" #import "Dock.h" #impo RT "DockBtn.h" #import "Column.h"//main controller The height of the dock below #define Kdockheight @interface Beyondviewcontroller () {//from plist
  
  An array of Column objects loaded in Nsmutablearray *_columns;
  
  Dock Options Bar under the main controller dock *_dock;
Record the currently selected child controller to remove its view from the parent controller's view to prepare Uiviewcontroller *_CURRENTCHILDVC for adding a new child controller view;
  
@end @implementation Beyondviewcontroller-(BOOL) Prefersstatusbarhidden {return NO;

  }-(void) viewdidload {[Super viewdidload];
  0. From the plist loading column array, traversing the array, according to the dictionary, generate a Column object, stored in the Column object array _columns = [Nsmutablearray array];
  NSBundle *mainbundle = [NSBundle mainbundle]; NSString *fullpath = [maInbundle pathforresource:@ "Columnlist.plist" oftype:nil];
  
  Nsarray *arr = [Nsarray Arraywithcontentsoffile:fullpath];
    For (Nsdictionary *dict in arr) {column *column = [column Columnwithdict:dict];
  [_columns Addobject:column];
  
  }//1. Add dock below the main controller side [self adddock];
  
  2. Create all the child controllers at once and add them to the childviewcontrollers [self createallchildviewcontrollers] of the current controller after wrapping them with navigation;
  
  3. The default selection of the NO. 0 controller [self changechildviewatindex:0 andchildvcclassname:@ "Homeviewcontroller"];
  
4. Set the color theme style of the global navigation bar at once [self setglobalnavigationitemcolortheme];
  
  #pragma mark adds dock-(void) Adddock {//1. Add dock below _dock = [[[Dock alloc] init];
  2. Monitor the btn inside the dock, let the controller become the agent property of the dock, or assign the value __unsafe_unretained beyondviewcontroller *beyond = Self for the members of the Dock Blok; _dock.btnclickblock = ^ (dockbtn *btn) {//Call custom method, change child view, Parameter 1: index number, Parameter 2: The class name of the child controller [beyond CHANGECHILDVIEWATINDEX:BTN.
  Tag AndChildVCClassName:btn.viewControllerClassName];
  
  
  }; 3, set the dock frame _dock.frame = CGRectMake (0, Self.view.frame.size.height-kdockheight, Self.view.frame.size.width, kdockheight);
  Log (@ "_dock frame--%@", Nsstringfromcgrect (_dock.frame));
  
  4, add dock to the main controller side view [Self.view Addsubview:_dock]; 2. Iterate through the array of Column objects, add the dockbtn for the dock in bulk (column *column in _columns) {[_dock AddDockBtnWithIconName:column.columnI
  Mgname Title:column.columnName ViewControllerClassName:column.columnClassName];
  
}//3. Set Dock default to select the No. 0 [_dock setdockbtnclickedatindex:0]; ///custom method, change child view, Parameter 1: index number, Parameter 2: Child Controller class name-(void) Changechildviewatindex: (int) index Andchildvcclassname: (NSString *)
  Viewcontrollerclassname {log (@ "clicked%@", Viewcontrollerclassname);
    if (Self.childViewControllers.count > 0) {//0, first remove the new child controller, if the new sub controller is the current controller, go straight back OK?
    Uiviewcontroller *CHILDVC = [self childviewcontrollers][index];
    if (CHILDVC = = _CURRENTCHILDVC) return;
    
    1, first remove the view [_currentchildvc.view Removefromsuperview] of the previous child controller;
    
    2, add the view of the new sub controller to the master controllerChildVC.view.frame = CGRectMake (0, 20, 320, 416);
    Log (@ "Self view--%@", Nsstringfromcgrect (Self.view.frame));
    Log (@ "CHILDVC view--%@", Nsstringfromcgrect (ChildVC.view.frame));
    
    The view is not repeated, because once it is found that a view is added repeatedly, it is placed on top, preferably by removing the old view and adding a new view [Self.view AddSubview:childVC.view];
  3, important, the current child controller must be updated for next removal to prepare _CURRENTCHILDVC = CHILDVC; #pragma mark creates all the child controllers (altogether 5, first, message, I, squares, more)-(void) Createallchildviewcontrollers {//1. Iterate over the Column object array, create all the sub controllers in bulk, and use navigation control Wrapper, last added to the self childviewcontrollers array to save for (Column *column in _columns) {Class c = nsclassfromstring (column.column
    ClassName);
    Uiviewcontroller *CHILDVC =nil; if ([Nsstringfromclass (c) isequaltostring:@ "Moreviewcontroller"]) {//Special note: After inheriting tableview, to use the group style again, you must specify the
    The style is group, and here specifically refers to moreviewcontroller CHILDVC = [[C alloc]initwithstyle:uitableviewstylegrouped];
    else {CHILDVC = [[C Alloc]init]; //Set the navigation bar title ChildVC.navigationItem.title = column.cOlumnname;
  The method of overriding the parent class [self ADDCHILDVIEWCONTROLLER:CHILDVC]; }} #pragma Marck-overrides the parent class//To override the Addchildviewcontroller method-(void) Addchildviewcontroller in order to wrap all the navigation controllers when adding a child controller: ( Uiviewcontroller *) CHILDVC {Uinavigationcontroller *nav = [Uinavigationcontroller alloc]initwithrootviewcontroller:
  CHILDVC];
The child controller packaged as a navigation controller is added to the host controller so that each child controller has its own unique navigation bar [Super Addchildviewcontroller:nav]; //4. Set the color theme style on the global navigation bar at once-(void) Setglobalnavigationitemcolortheme {//1. Navigation bar//1.1. Operation NavBar quite operation all navigation bar UI in the application
  
  Navigationbar *navbar = [Uinavigationbar appearance]; 1.2. Set the navigation bar Uinavigationbar background picture (stretch) [NavBar setbackgroundimage:[uiimage imagestretchedwithname:@ Navigationbar_
  Background.png "] forbarmetrics:uibarmetricsdefault];
  1.3. Set the status bar background, no effect???
  
  
  [UIApplication sharedapplication].statusbarstyle = uistatusbarstylelightcontent; 1.4. Set the title Text property of the navigation bar Uinavigationbar, set the Nsmutabledictionary *navigationbartitledict by the dictionary = [nsmutabledictionary
  Dictionary];The foreground color, which is the colour of the text [navigationbartitledict Setobject:[uicolor Darkgraycolor] forkey:nsforegroundcolorattributename]; Text shadow cancellation, the dictionary can not put the structure, to use nsvalue packaging [navigationbartitledict setobject:[nsvalue Valuewithuioffset:uioffsetzero] ForKey
  
  
  : Nsshadowattributename];
  2. The item on the navigation bar Uibarbuttonitem *barbtnitem =[uibarbuttonitem appearance]; 2.1. Set background//button background [barbtnitem setbackgroundimage:[uiimage imagenamed:@ "Navigationbar_button_background.png"
  ] Forstate:uicontrolstatenormal Barmetrics:uibarmetricsdefault]; Background of button highlighting [Barbtnitem setbackgroundimage:[uiimage imagenamed:@ "Navigationbar_button_background_pushed.png"]
  Forstate:uicontrolstatehighlighted Barmetrics:uibarmetricsdefault]; Background when the button is unchecked [Barbtnitem setbackgroundimage:[uiimage imagenamed:@ "Navigationbar_button_background_disable.png"]
  
  
  Forstate:uicontrolstatedisabled Barmetrics:uibarmetricsdefault]; 2.2. Set Barbtnitem text attributes nsmutabledictionary *baritemtitledict = [Nsmutabledictionary dictiOnary];
  baritemdict text color [baritemtitledict setvalue:[uicolor darkgraycolor] forkey:nsforegroundcolorattributename];
  
  baritemdict fonts [baritemtitledict Setvalue:[uifont systemfontofsize:13] forkey:nsfontattributename];
  2.3. Use dictionary to set Barbtnitem caption text attributes [Barbtnitem settitletextattributes:baritemtitledict forstate:uicontrolstatenormal];
[Barbtnitem settitletextattributes:baritemtitledict forstate:uicontrolstatehighlighted];
 } @end

Dock.h


//Dock.h
//20_ handsome no Weibo////
Created by Beyond on 14-8-3.
Copyright (c) 2014 Com.beyond. All rights reserved.
The dock is a bar below the main controller, which consists of a button dockbtn

#import <UIKit/UIKit.h>
@class dockbtn;
@interface Dock:uiview
//Add an item to the Dock (View), the parameter is the icon name, and the caption to display, and the corresponding child controller class name

-(void) Adddockbtnwithiconname: (NSString *) iconname title: (NSString *) title Viewcontrollerclassname: (NSString *) Viewcontrollerclassname;

When a button in the dock is clicked, the code block is invoked to handle the corresponding click event
@property (copy,nonatomic) void (^btnclickblock) (DOCKBTN *);



A custom method that determines by code which DOCKBTN is clicked, and the parameter is the index of the button that will be clicked in the dock
-(void) Setdockbtnclickedatindex: (int) index;
@end

Dock.m

DOCK.M//20_ handsome no Weibo////Created by Beyond on 14-8-3. Copyright (c) 2014 Com.beyond.
All rights reserved. This is the main controller below the column, Tabbar, also called the Dock, which has five buttons, is the home page, I, News, Plaza, more #import "Dock.h" #import "DockBtn.h" @interface Dock () {//when
The former selected the dockbtn dockbtn *_currentdockbtn; @end @implementation the Dock//Init method calls Initwithframne-(ID) initWithFrame: (CGRect) frame {self = [super Initwithfram
  E:frame]; if (self) {//Intrinsic fixed property, set dock background color (classification method, use imagename to tile) Self.backgroundcolor = [Uicolor colorwithpatternimagename
  d:@ "Tabbar_background.png"];
return self; //To provide an external interface, add a dockbtn (button) to the dock (View), the parameter is the icon name, and the title to display, and the corresponding child controller class name-(void) Adddockbtnwithiconname: (NSString *) Iconname title: (NSString *) title Viewcontrollerclassname: (NSString *) Viewcontrollerclassname {//1. Create a button inside the dock,
  and add to the dock inside dockbtn *dockbtn = [dockbtn buttonwithtype:uibuttontypecustom];
  
  [Self addsubview:dockbtn]; 2. Set the text displayed in Dockbtn normal state [dockbtn Settitle:title Forstate:uicontrolstatEnormal];
  
  3. The classification method, sets the button normal and the selected state picture, returns the picture size [dockbtn setbtnimgfornormalandselectedwithname:iconname];
  
  4. Set DOCKBTN corresponding Click, the class name of the child controller to be instantiated [dockbtn Setviewcontrollerclassname:viewcontrollerclassname]; 5. Listener clicks, as long as the response is pressed, (the event first passed to the dock method, the dock method by calling the property block blocks of code, and then calls to the main controller inside the code, because: the main controller instantiated in the dock, in the dock to instantiate the DOCKBTN , therefore, the primary controller does not know that the dockitem exists) [Dockbtn addtarget:self Action: @selector (Dockbtnclick:) forControlEvents:
  
  Uicontroleventtouchdown];
6. Traverse to set the frame of all the buttons in the dock (make it evenly distributed) [self setdockbtnframes]; }//Traversal set the frame of all buttons in the dock (so that it is evenly distributed)-(void) Setdockbtnframes {//1, get the number of buttons in the dock int dockbtnnum = Self.subviews.cou
  
  nt 2, according to the current number of dockbtn in the dock, calculate the width of each dockbtn (self is dock,320*44) cgfloat dockbtnwidth = self.frame.size.width/
  Dockbtnnum;
  
  CGFloat dockbtnheight = self.frame.size.height;
    
    for (int i = 0; i < Dockbtnnum i++) {//1. Remove child controls one by one dockbtn *btn = self.subviews[i]; 2. Calculates its x btn.frame = CGRectMake (i * dockbtnwidth, 0, do) according to the indexCkbtnwidth, Dockbtnheight);
      3. Initialization, the No. 0 btn (that is, the first page) selected if (i = = 0) {btn.selected = YES; Most importantly, it will be selected, as the current button, remember with the member variable, when you click on the button on the dock, you first put it unchecked, then click on the button selected, and finally, the most important thing is to reset the clicked button to the current button, with the member variable to remember _
    CURRENTDOCKBTN = BTN;
  //4. Because click the button in the dock, you know which button clicked, so give each button a tag, as its index btn.tag = i; }//Most importantly, when clicking on the button on the dock, first place the current as unchecked, then click on the button selected, and most importantly, reset the clicked button to the existing button and remember with the member variable-(void) Dockbtnclick: (
  
  DOCKBTN *) BTN {//1. Let the current btn be deselected _currentdockbtn.selected = NO;
  
  2. Let the new btn select btn.selected = YES;
  
  3. Finally, let the new btn become the currently selected BTN _currentdockbtn = btn;
    4. Call block, which is passed through the main control of the code blocks, the purpose is to deal with the click of the corresponding sub controller if (_btnclickblock) {//Pass the parameter dockbtn passed, to the main controller, which the member variable remember its corresponding controller class name
  _btnclickblock (BTN); ///custom method, through the code to determine which DOCKBTN was clicked, the argument is the dock bar that will be clicked on the button index-(void) Setdockbtnclickedatindex: (int) index {//1.robust
  
  Judge if (Index < 0 | | | index >= self.subviews.count) return; 2. Get the corresponding dockbtn Viewwithta by indexG also line dockbtn *btn = Self.subviews[index];
3. Manually call the following method, which is equivalent to the user's hand click the corresponding button in the dock [self dockbtnclick:btn];
 } @end

DockBtn.h


//DockBtn.h
//20_ handsome no Weibo////
Created by Beyond on 14-8-4.
Copyright (c) 2014 Com.beyond. All rights reserved.
A dockbtn represents a button on the dock, which has a member that is the class name of the corresponding child controller, such as the home button, and the value of the member property is called: Homeviewcontroller

#import <uikit/uikit.h >

@interface Dockbtn:uibutton
//Each DOCKBTN, use a member to remember its corresponding controller's class name
@property (nonatomic,copy) NSString * Viewcontrollerclassname;
@end

Dockbtn.m

DOCKBTN.M//20_ handsome no Weibo////Created by Beyond on 14-8-4. Copyright (c) 2014 Com.beyond.
All rights reserved. A dockbtn represents a button on the dock, which has a member that is the class name of the corresponding sub controller, such as the home button, and the value of the member property is called: Homeviewcontroller #import the total width of the contents of the "DockBtn.h"//button Define Kbtncontentwidth The total height of the contents of the ContentRect.size.width//button #define Kbtncontentheight contentRect.size.height// The height ratio of the picture in the button #define the height of the text label in the Kimageheightratio 0.6//button #define Klabelheightratio (1-kimageheightratio) @imple
  Mentation DOCKBTN//Some of the default generic properties must be written inside the constructor-(ID) initWithFrame: (CGRect) frame {self = [super Initwithframe:frame];
    if (self) {//1. Set Button Text properties (in Bureau, font size) self.titleLabel.textAlignment = Nstextalignmentcenter;
    
    Self.titleLabel.font = [Uifont systemfontofsize:12];
    2. Set the button picture properties (enlarge mode, cancel the button default click when highlighting the color) Self.imageView.contentMode = Uiviewcontentmodescaleaspectfit;
    
    Suppresses the default button-click Highlight Color (image is drawn darker when highlighted or pressed) self.adjustsimagewhenhighlighted = NO; 3. Classification method, set buttonBackground when selected [self setbgimgforselected:@ "tabbar_slider.png"];
return self; #pragma mark overrides the method of the parent class (overwriting the behavior of the parent class as it was highlighted)-(void) sethighlighted: (BOOL) highlighted {//Because this is just a picture of the button's checked and default state, you want to cancel some of the highlighted state Default discoloration behavior//Here is nothing to write, that is, cancel, the button itself in the highlight of the performance of those actions} #pragma mark returns the border of the Uiimageview inside the button (the picture in the button is above, centered)-(CGRect) Imagerectforc Ontentrect: (cgrect) Contentrect {//To center, the quickest way is to let the picture width and button in the button as wide return CGRectMake (0, 0, Kbtncontentwidth, Kbtncontenthei
Ght * kimageheightratio); #pragma mark returns the border of the Uilabel inside the button (the text in the button is centered below)-(CGRect) Titlerectforcontentrect: (cgrect) Contentrect {//To center, the quickest way is to let the
  Ching's label width and button width/y is located 5 units above the bottom line of the picture, that is, 5 cgfloat from the top of the picture labely = Kbtncontentheight * KIMAGEHEIGHTRATIO-5;
  The height of the text is the remaining height of the button cgfloat labelheight = kbtncontentheight-labely;
Return CGRectMake (0, LabelY, Kbtncontentwidth, labelheight);
 } @end

Model Column.h


//Column.h
//20_ handsome no Weibo////
Created by Beyond on 14-8-4.
Copyright (c) 2014 Com.beyond. All rights reserved.
The 1 column model corresponds to a button above the dock, and the category

#import <Foundation/Foundation.h>

//Data model represents a column
@interface column: NSObject

//Column name
@property (nonatomic,copy) nsstring *columnname;
Column Picture name
@property (nonatomic,copy) nsstring *columnimgname;
column corresponding to the controller class name
@property (nonatomic,copy) nsstring *columnclassname;
UI controls are weak, strings are copy, and other objects use strong

//Provide a class method, a constructor, that returns the object that encapsulates the data (the return ID can also)
+ (Column *) columnnamed: (NSString * ) ColumnName imgname: (nsstring*) columnimgname className: (NSString *) columnclassname;

class method, the dictionary-turn object resembles a JavaBean one-time fill
+ (Column *) Columnwithdict: (Nsdictionary *) dict;

Object method, after setting the object's properties, returns the object
-(Column *) Initwithdict: (Nsdictionary *) dict;

@end

Model COLUMN.M

////COLUMN.M//20_ handsome no Weibo///Created by Beyond on 14-8-4.//Copyright (c) 2014 Co
M.beyond. All rights reserved. #import "Column.h" @implementation column//Returns an object instance containing the name of the column's corresponding controller + (column *) columnnamed: (NSString *) ColumnName I Mgname: (NSString *) columnimgname className: (NSString *) Columnclassname {//To use the self Column for compatible subclasses *column = [[Self allo
  C]init];
  Column.columnname = ColumnName;
  Column.columnimgname = Columnimgname;
  Column.columnclassname = Columnclassname;
return column; ///class method, the dictionary-turn object is similar to JavaBean a one-time fill + (Column *) Columnwithdict: (Nsdictionary *) Dict {//is just the Initwithdict method of invoking the object, and self is used for
A compatible return for the child class [[Self alloc]initwithdict:dict]; }//Object method, after setting the properties of the object, returns the object-(Column *) Initwithdict: (Nsdictionary *) dict {/////The Init method of the parent class NSObject must first be invoked if (self = [Super I
  NIT]) {//Set the object's own properties [self setvaluesforkeyswithdictionary:dict];
//Returns the filled object return self; } @end 

The data source of the five columns button in the dock columnlist.plist


Related Article

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.