Ios-ui Summary

Source: Internet
Author: User

1. Start animation after program start

After the program starts, it can load a simple animation interface to introduce the program or user information.

You can use a xib to describe the interface. And if you want to load this xib file first after the program is loaded, you need to manually load the Xib in Appdelegate

With the Stroyboard boot, the view with the controller does not add to the window when the program is started, which belongs to lazy loading category

Called when the program starts to complete

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary*) launchOptions {

Override point for customization after application launch.

Create window

Self.window = [[Uiwindowalloc] initwithframe:[uiscreenmainscreen].bounds];

Load Storyboard

Uistoryboard *story = [uistoryboardstoryboardwithname:@ "Main" bundle:nil];

Uiviewcontroller *VC = [Story Instantiateinitialviewcontroller];

Self.window.rootViewController = VC;

Display window

[Self.windowmakekeyandvisible];

Loading the Welcome screen

Welcomview *welcome = [Welcomview Welcomview];

Setting Location and Dimensions

Welcome.frame = Self.window.bounds;

Insert to outermost

[Self.window Addsubview:welcome];

Returnyes;

}

In Xib, if you want to animate an internal child control, and the animation and the main interface appear with a delay, you need to implement it in one of the following methods.

When a view is added to a window, it calls the method Didmovetowindow and then calls Didmovetosuperview

-(void) Didmovetowindow

{

NSLog (@ "%s", __func__);

}

This method is called when the view is added to the window

The animation of the subsequent controls is written in this method

-(void) Didmovetosuperview

{

NSLog (@ "%s", __func__);

}

Back to top 2, launchscreen.xib

The Xib file automatically generated by this system will be loaded automatically when the app starts, and you can add some controls inside it, but

Note: The Launchscreen is higher than the launchimage priority.

Setting launchimage you need to be aware that the default emulator size is related to the startup picture.

Called when the class is loaded

When the program starts, it calls

+ (void) load

{

NSLog (@ "%s", __func__);

}

The current class or his subclass is called the first time it is used.

+ (void) initialize

{

NSLog (@ "%s", __func__);

}

Back to top 3, add custom reminders to plugins

Custom categories to let this method pop up loading picture reminders

#import "Uiimage+slqimage.h"

@implementation UIImage (Slqimage)

Renders a photo according to the original picture, the default navigation bar renders the bit blue

+ (Instancetype) Imagewithoriimage: (NSString *) imageName

{

UIImage *image = [UIImage imagenamed:imagename];

return [Image imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];

}

@end

Add this method to the plugin to compile and run again.

Open the plug-in project, locate the configuration file, be a plist file, and then add the required entries.

Back to top 4, adding attributes to the category will only generate the set and get methods

#import <UIKit/UIKit.h>

@interface UIView (Slqframe)

Category cannot generate member properties

Get,set methods and member properties are automatically generated

@property if only the declaration of the Get,set method is generated in the taxonomy, the member properties are not generated.

@property (nonatomic, assign) cgfloat height;

@property (nonatomic, assign) cgfloat width;

@property (nonatomic, assign) CGFloat x;

@property (nonatomic, assign) CGFloat y;

@end

Back to top 5, how to throw an exception

Nsinteger count = Items.Count; Number of buttons

Determines whether the number of columns is a multiple of 3, and throws an exception if not

if (count% 3)

{

Run out of exception

NSException *excep = [NSException exceptionwithname:@ "Wrong Number of columns" reason:@ "Number of columns is not a multiple of 3" userinfo:nil];

[Excep raise];//throws an exception

}

Run results

Terminating app due to uncaught exception ' number of columns is wrong ', Reason: ' Number of columns is not a multiple of 3 '

Back to top 6, custom Tabbar default Barbar display the picture height cannot exceed 44, if greater than 44 shows a problem, this is customizable Tabbar. 6.1, a new class Slqtabbar, because the number of Tabbar is not deterministic, so need to be imported, here using the model array to set.

Imitate the next Uitabbar

Uitabbar inside the button by Uitabbarcontroller's sub-controller

@interface Slqtabbar:uiview

Model Array (Uitabbaritem), directly using the system model

@property (nonatomic, strong) Nsarray *items;

@end

6.2. The model array can only be added once at initialization, so lazy loading is used.

@interfaceSLQTabBar ()

@property (nonatomic, weak) Slqtabbarbutton *selected; Whether the button is selected

@end

-(void) Setitems: (Nsarray *) items

{

_items = items;

Uitabbaritem Save the picture on the button, add in order

for (Uitabbaritem * bar in items) {

Use a custom button to suppress the highlight state

UIButton *btn = [Slqtabbarbuttonbuttonwithtype:uibuttontypecustom];

Set label

Btn.tag = Self.subviews.count;

Set background

[Btn SetBackgroundImage:bar.imageforState:UIControlStateNormal];

[Btn setBackgroundImage:bar.selectedImageforState:UIControlStateSelected];

Add a button to press the response event

[Btn addtarget:selfaction: @selector (Btnclick:) Forcontrolevents:uicontroleventtouchdown];

[Self addsubview:btn];

if (Self.subviews.count = = 1) {

The first one is selected by default

[Self btnclick:btn];

}

}

}

6.3, Tabbar is a row of buttons arranged, but no highlight state, only normal and selected state.

This only requires a way to rewrite the UIButton. Create a new class that inherits from UIButton, overriding the sethighlighted method

#import "SLQTabBarButton.h"

@implementation Slqtabbarbutton

Cancel Button Highlight State

-(void) sethighlighted: (BOOL) highlighted

{}

@end

6.4, each time you add a button after the layout of the button

-(void) layoutsubviews

{

[Superlayoutsubviews];

int count = (int) self.subviews.count;

Calculate button width by screen width

for (int i = 0;  I < count; i + +) {

CGFloat x = 0;

CGFloat y = 0;

CGFloat w = [Uiscreenmainscreen].bounds.size.width/count;

CGFloat h = self.bounds.size.height;

Slqtabbarbutton *btn = self.subviews[i];

x = i * w;

Btn.frame = CGRectMake (x, Y, W, h);

}

}

6.5, the response button click, use the agent to pass data

Defined

@classSLQTabBar;

Add Agent, Response button click

@protocol slqtabbardelegate <NSObject>

@optional

-(void) TabBar: (Slqtabbar *) TabBar Didclickbutton: (nsinteger) index;

@end

Statement

@property (nonatomic, weak) id<slqtabbardelegate> delegate;

Use

-(void) Btnclick: (UIButton *) btn

{

Uncheck Previous button

_selected.selected = NO;

Select the current button

btn.selected = YES;

Record the selected button

_selected = BTN;

Switch the controller, add an agent, first determine if there is this method

if ([Self.delegate respondstoselector: @selector (Tabbar:didclickbutton:)])

{

Send a message to the agent, through the button tag to determine which button

[Self.delegate tabbar:self DidClickButton:btn.tag];

}

}

6.6, the specific use method, in the controller set Tabbar

Add the custom Tabbar to Tabbar, and then delete the system-generated button.

Add custom Tabbar to Tabbar, and then delete the system-generated button

-(void) Setalltabbar

{

Remove all child controls

[Self.tabbar Removefromsuperview];

Add Custom Tabbar

Slqtabbar *bar = [[Slqtabbar alloc] init];

Incoming model data

Bar.items = Self.items;

Set Dimensions

Bar.frame = Self.tabBar.bounds;

Set up the agent, listen button click

Bar.delegate = self;

Add to Tabbar, but remove the button that comes with the system

[Self.tabbar Addsubview:bar];

}

Remove System button

-(void) Viewwillappear: (BOOL) animated

{

[Super viewwillappear:animated];

Remove Tabbar from your system

For (UIView *childview in self.tabBar.subviews) {

if (![ Childview Iskindofclass:[slqtabbar class]) {

[Childview Removefromsuperview];

}

}

}

Monitor button click

-(void) TabBar: (Slqtabbar *) TabBar Didclickbutton: (nsinteger) index

{

NSLog (@ "%s--%d", __func__,index);

Switch Controller

Self.selectedindex = index;

}

Back to top 7, manually add PCH files to all items

The PCH file contains something that can be used in every file in the project.

Back to top 8, load and initialize

When the program starts, it calls

+ (void) load

{

}

The current class or his subclass is called the first time it is used.

+ (void) initialize

{}

Back to top 9, add cover to any pop-up window

This is also more common, such as pop-up interface, the other parts of the program are gray background, and can not click.

You can add a gray view to the program, and before all the interfaces are displayed, you can use the

[UIApplication Sharedapplication].keywindow;

The window that is added to this window defaults to the front.

To customize a class that inherits from UIView, add two methods.

Screen size

#define Slqscreenbounds [UIScreen mainscreen].bounds

Main Window

#define Slqkeywindow [UIApplication Sharedapplication].keywindow

Show masking

+ (void) show

{

Get the main window and add a view to the main window

UIView *view = [[Slqcoverview alloc] initwithframe:slqscreenbounds];

View.backgroundcolor = [Uicolorblackcolor];

View.alpha = 0.4;

Add window to main window, display on top

[Slqkeywindow Addsubview:view];

}

Hide Cover

+ (void) Hide

{

Remove the child window and first determine if the Slqcoverview type of view

For (UIView *childview in slqkeywindow.subviews) {

if ([Childview iskindofclass:self]) {

[Childview Removefromsuperview];

}

}

}

Back to Top 10, Loadview, Viewdidload and Viewdidunload

Loadview Apple Design This method is for us to customize the view of Uiviewcontroller

Viewdidload Add other controls to view after creating a view of the controller

When the Viewdidunload system issues a memory warning

Relationship

1. When you first access the Uiviewcontroller view, the view is nil, and then the Loadview method is called to create the view

The Viewdidload method is called when the 2.view is created to initialize the interface element

3. When a memory warning occurs, the system may release Uiviewcontroller view, assign the view to nil, and call the Viewdidunload method

4. When accessing Uiviewcontroller view again, the view has been assigned nil in 3, so the Loadview method is called to recreate the view

After the 5.view is recreated, the Viewdidload method is called to initialize the interface element

11, Uinavigationbar generated pictures are processed view, blue

Original picture

The default two-times view is blue, so return an original image

UIImage *image = [uiimageimagenamed:@ "Cs50_activity_image"];

Set how the picture is rendered as the original picture

image = [Image imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];

Self.navigationItem.leftBarButtonItem = [[Uibarbuttonitem alloc] Initwithimage:imagestyle: Uibarbuttonitemstyleplain target:self Action: @selector (Activebtnclick)];

Ios-ui Summary

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.