Iphone development my Sina Weibo client-User Login waiting (1.4)

Source: Internet
Author: User

Based on the previous article, this article completed the user login wait function as shown in Figure 2. First, let's talk about the origin of this page function, this is to query the user records from the table when checking that there is already a user account in the sqlite database, and then obtain the Last Logon account from NSUserDefaults, if the queried user record contains the account for the last logon, use this account as the default display account. If not, use the first account in the user record as the default display account, in the previous article, this page is displayed when the user saves the account information to the sqlite library after completing OAuth authentication.

First, let's take a look at how the UI is implemented. The UI contains three elements, namely, the user profile icon, user name, and three functional buttons (ADD, switch, and delete, my approach is to add these three elements to a separate UIView, set the UIView background to transparent, and then display the UIView on the View of LoginViewController in the previous article, in this way, the UIView has a background image, which is provided by the View of LoginViewController. At the same time, the LoginViewController has an omission in the previous article. I forgot to add a background image to the View of LoginViewController. Here, I add the background image as follows:

Previous Article: Double-click LoginViewController. xib file. After enabling IB, double-click LoginViewController. open the View of xib, drag an Image View component from the Library panel to the View, set the size of the Image View as large as the View, and then set a background Image for the Image View, for example:

After completing the above content, I will go back to the topic and continue to talk about the functions of this article.

1. As mentioned above, a new independent UIView is created as the interface metadata handler of this function. Here, a class file of the UIViewController subclass type named SelectViewController is created first, remember to check the With XIB user interface option when creating a new interface.

2. Open the SelectViewController created in the previous step. h file, declare a UIButton as a small icon of the user's profile picture, a UILabel as the user name, and delegate and onClick to call the method in LoginViewController, and also import a UICustomSegmentedControl. h file. This is a custom component used to implement the three buttons mentioned above. This component is similar to the UISegmentedControl component that comes with the system, as for the reason why you have to create one by yourself instead of having to use the system, I will post the code of this component here without explaining how to directly use this component. The specific code is as follows:

# Import <UIKit/UIKit. h>

# Import "Global. h"

# Import "UICustomSegmentedControl. h"

@ Interface SelectViewController: UIViewController <UICustomSegmentedControlDelegate> {

IBOutlet UIButton * iconBtn;

IBOutlet UILabel * nameLabel;

Id delegate;

SEL onClick;

}

@ Property (nonatomic, retain) IBOutlet UIButton * iconBtn;

@ Property (nonatomic, retain) IBOutlet UILabel * nameLabel;

@ Property (nonatomic, retain) id delegate;

-(Id) initWithDelegate :( id) aDelegate onClick :( SEL) aOnClick; @ end

3. Double-click SelectViewController. xib is opened with IB. In the Library panel, drag a UIButton and UILabel to the appropriate position in the View and connect them to SelectViewController. iconBtn and nameLabel in h, set the View background to clear color, and save the settings, for example:

4. Open the SelectViewController. m file. First, use the initWithDelegate method. This method mainly sets the delegate and delegate of SelectViewController. The Code is as follows:

-(Id) initWithDelegate :( id) aDelegate onClick :( SEL) aOnClick; {if (self = [super init]) {self. delegate = aDelegate; onClick = aOnClick;} return self;} 5. Next, we need to set the background of the white box and the default small icon of the user profile picture (iconBtn). The implementation code is very simple, add the following code in the viewDidLoad method:

[IconBtn labels: [[Global pngWithPath: @ "icon_bg"] labels: 8.0 topCapHeight: 7.0] forState: UIControlStateNormal]; [iconBtn setBackgroundImage: [Global pngWithPath: @ "icon_h_bg"] condition: 8.0 topCapHeight: 7.0] forState: Unknown]; [iconBtn setImage: [Global pngWithPath: @ "user_icon"] forState: UIControlStateNormal]; [iconBtn setImage: [Global pngWithPath: @ "user_icon"] forState: UIControlStateHighlighted]; 6. Next we need to implement three function buttons (ADD, switch, and delete ), as mentioned above, this function is implemented by the custom component UICustomSegmentedControl. In the viewDidLoad method, instantiate a UICustomSegmentedControl and add it to the appropriate position in the View of SelectViewController. Five parameters are required when uicustomsegmented, the Code is as follows:

Optional * segmented = [[financialloc] initWithSegmentCount: 3 segmentsize: CGSizeMake (85.0f, 46.0f) dividerImage: [Global pngWithPath: @ "line"] tag: 99909 delegate: self]; segmented. center = CGPointMake (self. view. bounds. size. width/2, self. view. bounds. size. height-64); [self. view addSubview: segmented]; [segmented release]; 7. before using the UICustomSegmentedControl component, you must implement the following methods:

// Construct the sub-button-(UIButton *) buttonFor :( UICustomSegmentedControl *) segmentedControl atIndex :( NSUInteger) segmentIndex; {UIButton * button = [UIButton buttonWithType: Success]; button. frame = CGRectMake (0.0f, 0.0f, segmentedControl. segmentSize. width, segmentedControl. segmentSize. height); button. adjustsImageWhenHighlighted = NO; button. titleLabel. font = [UIFont systemFontOfSize: 15.0f]; [button setTitleColor: [UIColor colorWithRed: 50366f/255.0f green: 79366f/255.0f blue: 133.0f/255.0f alpha: 1.0f] forState: Large]; if (segmentIndex = 0) {[button setBackgroundImage: [[Global pngWithPath: @ "left_btn"] condition: 10.0 topCapHeight: 23.0] forState: UIControlStateNormal]; [button setBackgroundImage: [[Global pngWithPath: @ "left_h_btn"] Priority: 10.0 topCapHeight: 23.0] forState: Unknown]; [button setImage: [Global pngWithPath: @ "add"] forState: UIControlStateNormal]; // [button setImage: [Global pngWithPath: @ "add"] forState: UIControlStateHighlighted]; [button setTitle: @ "add" forState: UIControlStateNormal];} else if (segmentIndex = 1) {[button setBackgroundImage: [[Global pngWithPath: @ "center_btn"] condition: 1.0 topCapHeight: 23.0] forState: UIControlStateNormal]; [button condition: [[Global pngWithPath: @ "center_h_btn"] response: 1.0 topCapHeight: 23.0] forState: Unknown]; [button setImage: [Global pngWithPath: @ "change"] forState: UIControlStateNormal]; // [button setImage: [Global pngWithPath: @ "change"] forState: UIControlStateHighlighted]; [button setTitle: @ "" forState: UIControlStateNormal];} else {[button setBackgroundImage: [[Global pngWithPath: @ "right_btn"] stretchableImageWithLeftCapWidth: 1.0 topCapHeight: 23.0] forState: UIControlStateNormal]; [button setBackgroundIma

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.