UI02_基本控件

//
// ViewController.m
// UI02_基本控件
//
// Created by lanou on 16/1/15.
// Copyright © 2016年 lanou. All rights reserved.
//

import “ViewController.h”

@interface ViewController ()

@end

@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    //=========================================

pragma -mark 这里讲UILable

//创建UILable
UILabel *la = [[UILabel alloc]initWithFrame:CGRectMake(50, 100, 300, 100)];
//背景色
la.backgroundColor = [UIColor yellowColor];
//添加
[self.view addSubview:la];
//显示文字
la.text = @"百度贴吧卖血友病吧,丧心病狂!李彦宏出面澄清,越描越黑!";
//文字颜色
la.textColor = [UIColor blueColor];
//文字大小
//la.font = [UIFont systemFontOfSize:25];//系统25号字
//la.font = [UIFont boldSystemFontOfSize:25];//系统25号字加粗效果
la.font = [UIFont fontWithName:@"CourierNewPS-BoldItalicMT" size:25];
//字体对齐方式
la.textAlignment = NSTextAlignmentCenter;//居中
//阴影
la.shadowColor = [UIColor orangeColor];//阴影色
la.shadowOffset = CGSizeMake(2, 2);//偏移
//多行显示(保证宽度足够)
la.numberOfLines = 2;
//断行方式
la.lineBreakMode = NSLineBreakByTruncatingMiddle;
//圆角
la.layer.cornerRadius = 10;
la.layer.masksToBounds = YES;
//边框
la.layer.borderColor = [UIColor redColor].CGColor;
la.layer.borderWidth = 1;

/*
 创建一个lable显示一段文字
 字体大小加粗20号
 字体颜色.用RGB设置紫色
 文字居中
 阴影效果,颜色为黄色
 显示一行
 断行在中间
 边角弧度5
 边框颜色黑色.宽度为1
 */

pragma -mark 这里讲UITextFideld

UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(20, 250, 300, 50)];
tf.backgroundColor = [UIColor cyanColor];
[self.view addSubview:tf];
//提示文字
tf.placeholder = @"请输入密码...";
//密码显示...
tf.secureTextEntry = YES;
//清楚按钮
tf.clearButtonMode = UITextFieldViewModeAlways;
//键盘的样式
tf.keyboardType = UIKeyboardTypeDefault;
//return键的样式
tf.returnKeyType = UIReturnKeyGo;
//无效
//tf.enabled = NO;
//自定义键盘
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 375, 150)];
view.backgroundColor = [UIColor yellowColor];
//tf.inputView = view;
//键盘上方的选项
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 375, 40)];
view1.backgroundColor = [UIColor grayColor];
//tf.inputAccessoryView = view1;

//左侧视图 右侧视图
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
view2.backgroundColor = [UIColor blackColor];
tf.leftView = view2;
tf.leftViewMode = UITextFieldViewModeAlways;

//获取授权
tf.delegate = self;

pragma -mark UITextFideld 的代理方法

/*
 使用系统代理方法的三个步骤
 1,遵循协议
 2,获取授权
 3,实现方法
 */

pragma -mark UIButton

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(50, 350, 200, 70);
button.backgroundColor = [UIColor orangeColor];
[self.view addSubview:button];
//设置文字
[button setTitle:@"确定" forState:UIControlStateNormal];
//背景图片
//图片类
//jpg 必须加.jpg 而png不需要
UIImage *image = [UIImage imageNamed:@"111.jpg"];
[button setBackgroundImage:image forState:UIControlStateNormal];
//字体颜色
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//前景图片
UIImage *image1 = [UIImage imageNamed:@"222"];
[button setImage:image1 forState:UIControlStateNormal];
//调整按钮中图片的位置
//逆时针(上 左 下 右)
[button setImageEdgeInsets:UIEdgeInsetsMake(0, 40, 0, 0)];
//调整文字在按钮中的位置
//[button setTitleEdgeInsets:];
[button addTarget:self action:@selector(youTouchMe:) forControlEvents:UIControlEventTouchUpInside];

}
//点击按钮执行的方法
-(void)youTouchMe:(UIButton *)bu
{
[bu setTitle:@”取消” forState:UIControlStateNormal];

//弹出提示框
//UIAlertView *alt = [[UIAlertView alloc]initWithTitle:@"友情提示" message:@"是否已满18周岁" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
//显示
//[alt show];

//UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"友情提示" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"其他", nil];
//[sheet showInView:self.view];

}
//使用UIActionSheet的代理方法
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@”%ld”,buttonIndex);
}

//使用UIalertView的代理方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
NSLog(@”正在打开网页”);
}else{
NSLog(@”注意身体……”);
}
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
//判断用户输入的内容
NSString *inpiut = textField.text;
if ([inpiut isEqualToString:@”ilove”]) {
NSLog(@”i love too”);
}

//取消键盘
//[textField endEditing:YES];
[textField resignFirstResponder];
return YES;

}
//其他代理方法
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
NSLog(@”将要开始编辑”);
return YES;
}
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
NSLog(@”开始编辑”);
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
NSLog(@”将要结束编辑”);
return YES;
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
NSLog(@”结束编辑”);
}
//======================================
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

/*

pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值