ios 初级入门 (一)

//1.程序入口 AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


    MainViewController * vc =[[MainViewController alloc]init];
    UINavigationController * nav=[[UINavigationController alloc]initWithRootViewController:vc];
    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];


}




//2.绘制,找到你自己创建的ViewController中的如下方法开始绘制吧


- (void)viewDidLoad {
    [super viewDidLoad];
    //设置全屏
    [super.navigationController setNavigationBarHidden:true animated:TRUE];
    [super.navigationController setToolbarHidden:true animated:TRUE];


    //调用绘制标签函数
    [self drawLabel];


    //调用绘制单行文本框
    [self drawTextField];


 }


 #pragma 创建标签
- (void)drawLabel{
    //创建标签
    UILabel *uiLabel=[[UILabel alloc]init];


    //添加到当前view中,view属于当前ViewController
    [self.view addSubview:uiLabel];


    //设置标签位置大小
    [uiLabel setFrame:CGRectMake(0, 0, 60, 40)];


    //设置标签文本颜色
    [uiLabel setTextColor:[UIColor whiteColor]];


    //设置标签文本
    [uiLabel setText:@"账号"];
}
#pragma 创建文本框
- (void)drawTextField{
//创建文本框、和UILabel一样
    CUITextField *textField=[[CUITextField alloc]init];


    [self.view addSubview:textField];


    [textField setFrame:CGRectMake(0, 0, 540, 40)];


//调用textField一些基本方法....
  [textField setTextColor:[UIColor redColor]];
  //调用textField一些属性...


//是否为密码框
    textField.isPwd=true;
    //长度限制,这里不涉及中文长度处理
    textField.maxLen=6;


}


#pragma 绘制button
-(void)drawButton{
    UIButton *btn=[[UIButton alloc]init];
    [self.view addSubview:btn];
    [btn setFrame:CGRectMake(0, 0, 100, 40)];
    //设置按钮上文字
    [btn setTitle:@"I'm UIButton" forState:UIControlStateNormal];
    //设置背景颜色
    [btn setBackgroundColor:[UIColor redColor]];
    //居中
    btn.contentHorizontalAlignment=UICollectionViewScrollPositionCenteredHorizontally;
    btn.titleLabel.textAlignment=NSTextAlignmentCenter;
    // 设置button背景为圆效果
    btn.layer.cornerRadius = 10;
    //位置微调
    [btn setTitleEdgeInsets:UIEdgeInsetsMake(0,0,3,5)];
    //文字大小
    btn.titleLabel.font=[UIFont systemFontOfSize:20];
    
    //设置title的字体居中
    btn.titleLabel.textAlignment = NSTextAlignmentCenter;
    
    //设置title在一般情况下为白色字体
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    //设置title在button被选中情况下为灰色字体
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    
    //添加点击事件
    [btn addTarget:self action:@selector(onClick) forControlEvents:UIControlEventTouchUpInside];
}


//3.页面跳转


-(void)onClick{
    NSLog(@"按钮点击事件");
//跳转到第二个页面TwoViewController    
TwoViewController *vController = [[TwoViewController alloc] init];
    [self.navigationController pushViewController:vController animated:true];
}


 




                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值