import "AppDelegate.h"
import "LTView.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
// 程序加载完成后,就会执行该代理方法,在该方法中,我们为应用程序创建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;
}
// 程序即将结束活跃状态(例如:应用程序运行中,突然来电,短信,下拉通知栏,按home键时)。一般在该方法中做一些必要信息的储存,和一些暂停动作。例如,如果正在进行时,要暂停游戏
- (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.
}
// 程序已经进入后台状态,如果程序长期在后台待着,有可能会退出,所以在该方法中,要进行一些 重要数据 的持久化。
- (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.
}
// 程序即将进入前台,一般是在程序由后台进入的时候会执行该方法
- (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.
}
// 程序已经变得活跃(程序启动或者由后台进入前台都会执行该方法)
- (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{
// 为了防止空间被恶意修改,某些值我们需要自己规定好,只把必要的修改开放
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;
}
// 懒加载 :本质原理是重写属性的get方法。好处就是当我们需要用到该对象的时候在进行初始化它,起到一个延时加载的作用
// Lable的懒加载
-(UILabel *)descLable{
// 当属性每次调用get方法时,首先判断对象是否存在,如果存在直接返回,如果不存在,再创建
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;
}