Swift Weibo visitor View

Source: Internet
Author: User

Modify Global Colors       
Uinavigationbar.appearance (). Tintcolor = Uicolor.orangecolor ()

Uitabbar. Appearance(). Tintcolor = uicolor. Orangecolor()

1. Create a basic view Baseview:uitableviewcontroller because the microblog shows Tablerview, the base view is also TableView

2. The following 4 controllers (first page find message i) are inherited Baseview:uitableviewcontroller

3. In Loadview, determine if login (flag) is true to display the microblog information (Super.loadview) (because the controller relationship is uitableviewcontroller->basicview-> Homeviewcontroller Basic If the Loadview method of calling the parent class is to display Homeviewcontroller directly) false invokes the Setupvisitor () method that you wrote to display the guest view

4.visitorview:uiview (UIView is enough,)

* Need to call initWithFrame construction method because this method is called in the hand layout to add and layout controls in this method

    Override Init (frame:cgrect) {        super.init (frame:frame)                setupui ()    }    required init (coder Adecoder:nscoder {        fatalerror ("init (coder:) have not been implemented")    }

* Lazy Loading controls

/MARK:-Lazy load controlresponsible for creating the control//icons    PrivateLazy var Iconview:uiimageview = Uiimageview (Image:uiimage (named:"Visitordiscover_feed_image_smallicon"))    //Small House    PrivateLazy var Homeiconview:uiimageview = Uiimageview (Image:uiimage (named:"Visitordiscover_feed_image_house"))    //Matte View-do not use Maskview    PrivateLazy var Maskiconview:uiimageview = Uiimageview (Image:uiimage (named:"Visitordiscover_feed_mask_smallicon"))    //Message Text    PrivateLazy var Messagelabel:uilabel ={let label=UILabel () Label.text="pay attention to some people, back here to see what surprises concern some people, back here to see what surprises"        //generally do not use pure blackLabel.textcolor =Uicolor.darkgraycolor () Label.font= Uifont.systemfontofsize ( -) Label.numberoflines=0label.textalignment=Nstextalignment.centerreturnLabel} ()    //Register button   PrivateLazy var Registerbutton:uibutton ={Let button=UIButton () button.settitle ("Register", ForState:UIControlState.Normal) Button.settitlecolor (Uicolor.orangecolor (), ForState:UIControlState.Normal) Button.setbackgroundimage (UIImage (named:"common_button_white_disable"), ForState:UIControlState.Normal)returnButton} ()    //Login Button   PrivateLazy var Loginbutton:uibutton ={Let button=UIButton () button.settitle ("Login", ForState:UIControlState.Normal) Button.settitlecolor (Uicolor.darkgraycolor (), ForState:UIControlState.Norma L) Button.setbackgroundimage (UIImage (named:"common_button_white_disable"), ForState:UIControlState.Normal)returnButton} ()

* Layout controls

 Privatefunc setupui () {//1. Adding ControlsAddsubview (IconView) addsubview (Maskiconview) addsubview (homeiconview) addsubview (message Label) Addsubview (Registerbutton) addsubview (Loginbutton)//2. Set the layout to add the layout to the view//"VIEW1.ATTR1 = view2.attr2 * multiplier + constant"//by default, automatic layout is not supported with pure code development, and if you want to support automatic layout, you need to//the translatesautoresizingmaskintoconstraints of the control is set to False/no//1> iconIconview.translatesautoresizingmaskintoconstraints =falseAddConstraint (Nslayoutconstraint (Item:iconview, Attribute:NSLayoutAttribute.CenterX, Relatedby:nslayoutrela tion. Equal, Toitem:self, Attribute:NSLayoutAttribute.CenterX, multiplier:1, Constant:0)) AddConstraint (Nslayoutconstraint (Item:iconview, Attribute:NSLayoutAttribute.CenterY, Relatedby:nslayoutre Lation. Equal, Toitem:self, Attribute:NSLayoutAttribute.CenterY, multiplier:1, Constant:- -))                //2> Small House-code design automatic layout, it is advisable to have a fixed referenceHomeiconview.translatesautoresizingmaskintoconstraints =falseAddConstraint (Nslayoutconstraint (Item:homeiconview, Attribute:NSLayoutAttribute.CenterX, Relatedby:nslayout Relation.equal, Toitem:iconview, Attribute:NSLayoutAttribute.CenterX, multiplier:1, Constant:0)) AddConstraint (Nslayoutconstraint (Item:homeiconview, Attribute:NSLayoutAttribute.CenterY, Relatedby:nslayo Utrelation.equal, Toitem:iconview, Attribute:NSLayoutAttribute.CenterY, multiplier:1, Constant:0))                //3> Setting TextMessagelabel.translatesautoresizingmaskintoconstraints =falseAddConstraint (Nslayoutconstraint (Item:messagelabel, Attribute:NSLayoutAttribute.CenterX, Relatedby:nslayout Relation.equal, Toitem:iconview, Attribute:NSLayoutAttribute.CenterX, multiplier:1, Constant:0)) AddConstraint (Nslayoutconstraint (Item:messagelabel, Attribute:NSLayoutAttribute.Top, Relatedby:nslayoutre Lation. Equal, Toitem:iconview, Attribute:NSLayoutAttribute.Bottom, multiplier:1, Constant: -))        //tip: If you want to set a fixed value, the referenced property needs to be set to Nslayoutattribute.notanattribute, the reference object is nilAddConstraint (Nslayoutconstraint (Item:messagelabel, Attribute:NSLayoutAttribute.Width, Relatedby: Nslayoutrelation.equal, Toitem:nil, Attribute:NSLayoutAttribute.NotAnAttribute, multiplier:1, Constant:224))                //4> Registration ButtonRegisterbutton.translatesautoresizingmaskintoconstraints =falseAddConstraint (Nslayoutconstraint (Item:registerbutton, Attribute:NSLayoutAttribute.Left, Relatedby:nslayoutr Elation. Equal, Toitem:messagelabel, Attribute:NSLayoutAttribute.Left, multiplier:1, Constant:0)) AddConstraint (Nslayoutconstraint (Item:registerbutton, Attribute:NSLayoutAttribute.Top, Relatedby:nslayout Relation.equal, Toitem:messagelabel, Attribute:NSLayoutAttribute.Bottom, multiplier:1, Constant: -)) AddConstraint (Nslayoutconstraint (Item:registerbutton, Attribute:NSLayoutAttribute.Width, Relatedby:nslayo Utrelation.equal, Toitem:nil, Attribute:NSLayoutAttribute.NotAnAttribute, multiplier:1, Constant: -)) AddConstraint (Nslayoutconstraint (Item:registerbutton, Attribute:NSLayoutAttribute.Height, Relatedby:nslay Outrelation.equal, Toitem:nil, Attribute:NSLayoutAttribute.NotAnAttribute, multiplier:1, Constant: *))                //5> Login ButtonLoginbutton.translatesautoresizingmaskintoconstraints =falseAddConstraint (Nslayoutconstraint (Item:loginbutton, Attribute:NSLayoutAttribute.Right, Relatedby:nslayoutrel ation. Equal, Toitem:messagelabel, Attribute:NSLayoutAttribute.Right, multiplier:1, Constant:0)) AddConstraint (Nslayoutconstraint (Item:loginbutton, Attribute:NSLayoutAttribute.Top, Relatedby:nslayoutrel ation. Equal, Toitem:messagelabel, Attribute:NSLayoutAttribute.Bottom, multiplier:1, Constant: -)) AddConstraint (Nslayoutconstraint (Item:loginbutton, Attribute:NSLayoutAttribute.Width, Relatedby:nslayoutr Elation. Equal, Toitem:nil, Attribute:NSLayoutAttribute.NotAnAttribute, multiplier:1, Constant: -)) AddConstraint (Nslayoutconstraint (Item:loginbutton, Attribute:NSLayoutAttribute.Height, Relatedby:nslayout Relation.equal, Toitem:nil, Attribute:NSLayoutAttribute.NotAnAttribute, multiplier:1, Constant: *))

Swift Weibo visitor View

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.