Swift Project-Imitation of group buying (the building of the main interface and some details of the homepage)

Source: Internet
Author: User

Before learning OC When writing a group buy project, now learn swift, take to write with Swift, is also Lianche with Mongolia, 1.1 points of the upward.

Today, the main shelf is set up.

There are: Uitabbarcontroller,uinavigationcontroller, and Navigationitem (this guy put a hole in my face, the one who was thinking about making the effect, the results came out, The middle of the Titleview is not centered)

In the navigation controller core code:

Initialize all child view controllers

Func SETALLCHILDVC () {

TABBARADDCHINDVC (Shouyetableviewcontroller (), title: "Home", ImageName: "Set _16.png", Selectedimagename: "Set _16.png")

TABBARADDCHINDVC (Tuangoutableviewcontroller (), title: "Buy", ImageName: "Set _18.png", Selectedimagename: "Set _18.png")

TABBARADDCHINDVC (Fujinviewcontroller (), title: "Near", ImageName: "Home _03.png", Selectedimagename: "Home _03.png")

}

Use VC as a navigation controller with view as the Uitabbarcontroller controller

Func TABBARADDCHINDVC (Vc:uiviewcontroller, title:string,imagename:string,selectedimagename:string) {

Vc.tabbaritem = Uitabbaritem (Title:title, Image:uiimage (Named:imagename), Selectedimage:uiimage (named: Selectedimagename))

Let nav2 = Mainnavigationcontroller (ROOTVIEWCONTROLLER:VC)

Addchildviewcontroller (NAV2)

}

About the navigation bar color and font size settings:

Self.navigationBar.barTintColor = Uicolor.orangecolor ()

Let navigationtitleattribute:nsdictionary = Nsdictionary (ObjectsAndKeys:UIColor.blackColor (), Nsforegroundcolorattributename)

Self.navigationBar.titleTextAttributes = Navigationtitleattribute as [Nsobject:anyobject]

On the homepage, is mainly a head view (instead of the partition header, when the partition head is set, it needs to set its height), using a custom view, to add the button, in its xib file (this file, when creating the view, is not allowed to tick, can only be created later, or some other method of it , be sure to pay attention to the root Code association, and at the time of loading, use the

Let headers = Nsbundle.mainbundle (). loadnibnamed ("Headview", Owner:self, Options:nil). Last as! Headview

Self.tableView.tableHeaderView = Header

To load the view.

As for, when clicking on the button on the view, you need to click on the button's event to the controller to handle, this use of the agent (the closure will not use Ah, the agent is not good, not happy)

In view:

Import UIKit

Protocol headviewdelegate:class{//represents this agent can only be implemented by one class

Func Clickedatnum (Clicked:int)

}

Class Headview:uiview {

Weak var delegate:headviewdelegate?

@IBAction func Headclick (Sender:uibutton) {

var Clicktag = delegate?. Clickedatnum (Sender.tag)

}

}

The controller is simply to abide by the Protocol, the implementation of the method, set itself as an agent on the line

Swift Project-Imitation of group buying (the building of the main interface and some details of the homepage)

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.