import "AppDelegate.h"
import "LTView.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
// 程序加載完成后,就會(huì)執(zhí)行該代理方法,在該方法中,我們?yōu)閼?yīng)用程序創(chuàng)建window等必要的界面
-
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[self.window setRootViewController:[[UIViewController alloc]init]];
NSLog(@"---%s", func);self.window.backgroundColor = [UIColor redColor];
LTView *view = [[LTView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
[view setTitleForLable:@"OOO"];
[view setTextFieldPlaceHolder:@"XXX"];
[view setColourForLable:[UIColor greenColor]];
[view setTextFieldBorderStyle :UITextBorderStyleBezel];
[self.window addSubview:view];LTView *view1 = [[LTView alloc]initWithFrame:CGRectMake(0, 50, 0, 0)];
[view1 setTitleForLable:@"XXX"];
[view1 setTextFieldPlaceHolder:@"OOO"];
[view1 setTextFieldBorderStyle :UITextBorderStyleBezel];[view addSubview:view1];
return YES;
}
// 程序即將結(jié)束活躍狀態(tài)(例如:應(yīng)用程序運(yùn)行中,突然來電,短信,下拉通知欄,按home鍵時(shí))。一般在該方法中做一些必要信息的儲(chǔ)存,和一些暫停動(dòng)作。例如,如果正在進(jìn)行時(shí),要暫停游戲
- (void)applicationWillResignActive:(UIApplication *)application {
NSLog(@"---%s",func);
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
// 程序已經(jīng)進(jìn)入后臺(tái)狀態(tài),如果程序長(zhǎng)期在后臺(tái)待著,有可能會(huì)退出,所以在該方法中,要進(jìn)行一些 重要數(shù)據(jù) 的持久化。
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSLog(@"---%s",func);
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
// 程序即將進(jìn)入前臺(tái),一般是在程序由后臺(tái)進(jìn)入的時(shí)候會(huì)執(zhí)行該方法
- (void)applicationWillEnterForeground:(UIApplication *)application {
NSLog(@"---%s",func);
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
// 程序已經(jīng)變得活躍(程序啟動(dòng)或者由后臺(tái)進(jìn)入前臺(tái)都會(huì)執(zhí)行該方法)
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSLog(@"---%s",func);
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
// 程序即將退出
- (void)applicationWillTerminate:(UIApplication *)application {
NSLog(@"%s",func);
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
import <UIKit/UIKit.h>
@interface LTView : UIView
// 為lable.text賦值的聲明
-(void)setTitleForLable:(NSString *)titleStr;
// 修改lable顏色
-(void)setColourForLable:(UIColor *)colour;
// 修改textField的密碼樣式
-(void)setTextFieldSecure:(BOOL)secure;
// 修改textField占位符
-(void)setTextFieldPlaceHolder:(NSString *)placeHolder;
// 修改邊框樣式
-(void)setTextFieldBorderStyle:(UITextBorderStyle)borderStyle;
@end
import "LTView.h"
@interface LTView ()
@property(nonatomic,retain) UILabel *descLable;
@property(nonatomic,retain) UITextField *contentTextField;
@end
@implementation LTView
-(instancetype)initWithFrame:(CGRect)frame{
// 為了防止空間被惡意修改,某些值我們需要自己規(guī)定好,只把必要的修改開放
CGRect myFrame = CGRectMake(0, frame.origin.y, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
self = [super initWithFrame:myFrame];
if (self) {
}return self;
}
// 懶加載 :本質(zhì)原理是重寫屬性的get方法。好處就是當(dāng)我們需要用到該對(duì)象的時(shí)候在進(jìn)行初始化它,起到一個(gè)延時(shí)加載的作用
// Lable的懶加載
-(UILabel *)descLable{
// 當(dāng)屬性每次調(diào)用get方法時(shí),首先判斷對(duì)象是否存在,如果存在直接返回,如果不存在,再創(chuàng)建
if (!_descLable) {
_descLable = [[UILabel alloc]initWithFrame:CGRectMake(80, 130, 60, 40)];
[self addSubview:_descLable];
}
return _descLable;
}
// textField的懶加載
-(UITextField *)contentTextField{
if (!_contentTextField) {
_contentTextField = [[UITextField alloc]initWithFrame:CGRectMake(170, 130, 100, 40)];
[self addSubview:_contentTextField];
}return _contentTextField;
}
// 為lable.text賦值
-(void)setTitleForLable:(NSString *)titleStr{
self.descLable.text = titleStr;
}
// 修改lable的顏色
-(void)setColourForLable:(UIColor *)colour{
self.descLable.backgroundColor = colour;
}
// 修改textField的密碼樣式
-(void)setTextFieldSecure:(BOOL)secure{
self.contentTextField.secureTextEntry = YES;
}
// 修改textField占位符
-(void)setTextFieldPlaceHolder:(NSString *)placeHolder{
self.contentTextField.placeholder = placeHolder;
}
-(void)setTextFieldBorderStyle:(UITextBorderStyle )borderStyle{
self.contentTextField.borderStyle = borderStyle;
}