[Code-only] Developing Sina Weibo in Swift 2.0 -- day 1, swift2.0

Source: Internet
Author: User

[Code-only] Developing Sina Weibo in Swift 2.0 -- day 1, swift2.0

Development Environment: Xcode 7 Beta 4


1.1: initial deployment architecture


1.2 set the root controller (AppDelegate. swift)

<span style="font-family:Microsoft YaHei;">   func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {        // Override point for customization after application launch.                window = UIWindow (frame: UIScreen.mainScreen().bounds )        window?.backgroundColor = UIColor.whiteColor()        window?.rootViewController = MainUITabBarController()        window?.makeKeyAndVisible()        return true    }</span>


1.3 custom TarbBar

<Span style = "font-family: Microsoft YaHei;"> import UIKitclass MainUITabBarController: UITabBarController {override func viewDidLoad () {super. viewDidLoad () // Do any additional setup after loading the view. addChildViewControllers () setComposeButton ()} // set the Button private func setComposeButton () {// calculate the Button height let w = tabBar. bounds. width/CGFloat (viewControllers !. Count) // Button existing width and height Rect let rect = CGRect (x: 0, y: 0, width: w, height: tabBar. bounds. height) // use offset to set the Button position composeButton. frame = CGRectOffset (rect, 2 * w, 0)} // Add all sub-controllers private func addChildViewControllers () {// Start add all sub-controllers javasaddchildviewcontroller (HomeTableViewController (), title: "Homepage", imageName: "tabbar_home") addChildViewController (MessageTableViewController (), title: "message", imageName: "tabbar_message_center") addChildViewController (UIViewController ()) addChildViewController (DiscoverTableViewController (), title: "", imageName: "tabbar_discover") addChildViewController (profileTableViewController (), title: "", imageName: "tabbar_profile ") // end certificate} // lazy create Button lazy private var composeButton: UIButton = {let button = UIButton () // Start to set the Button material ----------------------------------- button. setImage (UIImage (named: "tabbar_compose_icon_add"), forState: UIControlState. normal) button. setImage (UIImage (named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState. highlighted) button. setBackgroundImage (UIImage (named: "tabbar_compose_button"), forState: UIControlState. normal) button. setBackgroundImage (UIImage (named: "tabbar_compose_button_highlighted"), forState: UIControlState. highlighted) // end ------------------------------------------------- // you are not prompted to knock on self. tabBar. addSubview (button) button. addTarget (self, action: "ClickComposeButton", forControlEvents: UIControlEvents. touchUpInside) return button} () // Add Controller Method //-parameter vc: View Controller //-parameter title: title //-parameter imageName: image name private func addChildViewController (vc: UIViewController, title: String, imageName: String) {tabBar. tintColor = UIColor. orangeColor () vc. title = title vc. tabBarItem. image = UIImage (named: imageName) let nav = UINavigationController (rootViewController: vc) addChildViewController (nav)} </span>


1.4 set the logon interface through the inheritance relationship

Note: Determine whether to switch the interface based on whether the user logs on.

1.4.1 customize a controller that inherits the UITableViewController


1.4.2 modify the inheritance relationships of all controllers and inherit the BaseTableViewController


1.4.3 set the View of BaseTableViewController

<Span style = "font-family: Microsoft YaHei;"> // set custom logon View private func setVistorView () {// create an empty View, test Using view = UIView () // set the color view. backgroundColor = UIColor. orangeColor ()} </span>


1.4.4 override the loadView () method of BaseTableViewController

<Span style = "font-family: Microsoft YaHei;"> // defines whether a user is logged on to the switch. var userLogin = true </span>

<Span style = "font-family: Microsoft YaHei;"> override func loadView () {// determines whether the View userLogin is successfully switched during user logon? Super. loadView (): setVistorView ()} </span>

Update every day for 12 consecutive days

 

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.