美文网首页
ios学习笔记之ui按钮

ios学习笔记之ui按钮

作者: 云翻拥成夏 | 来源:发表于2016-07-11 18:30 被阅读0次

    #import"ViewController.h"

    @interfaceViewController()

    //标题标签

    @property(nonatomic,strong)UILabel*titleLable;

    //左边按钮

    @property(nonatomic,strong)UIButton*leftBtn;

    //右边按钮

    @property(nonatomic,strong)UIButton*rightBtn;

    //显示图片

    @property(nonatomic,strong)UIImageView*myImageView;

    @end

    @implementationViewController

    - (void)viewDidLoad {

    [superviewDidLoad];

    //定义标签位置与名称

    self.titleLable= [[UILabelalloc]initWithFrame:CGRectMake(150,50,150,30)];

    self.titleLable.text=@"表情帝";

    [self.viewaddSubview:self.titleLable];

    //定义做按钮的位置

    self.leftBtn= [[UIButtonalloc]initWithFrame:CGRectMake(20,150,45,45)];

    //定义按钮的图片

    UIImage*leftImage = [UIImageimageNamed:@"left_normal"];

    //设置左按钮的背景图片

    [self.leftBtnsetBackgroundImage:leftImageforState:(UIControlStateNormal)];

    [self.viewaddSubview:self.leftBtn];

    //显示相框名称

    self.myImageView= [[UIImageViewalloc]initWithFrame:CGRectMake(85,100,200,200)];

    UIImage*image = [UIImageimageNamed:@"biaoqingdi"];

    self.myImageView.image= image;

    //显示相框图片

    [self.viewaddSubview:self.myImageView];

    //设置右按钮的位置

    self.rightBtn=[[UIButtonalloc]initWithFrame:CGRectMake(305,150,45,45)];

    //设置右按钮的图片

    UIImage*rightImage = [UIImageimageNamed:@"right_normal"];

    //设置右按钮的背景图片

    [self.rightBtnsetBackgroundImage:rightImageforState:(UIControlStateNormal)];

    [self.viewaddSubview:self.rightBtn];

    //self.lable.text =@"阿桃";

    }

    -(void)btnClickLister

    {

    NSLog(@"click

    btn");

    }

    -(void)demo {

    //UIView *view =[u]

    //按钮UIButton

    //UIButton *button =[UIButton buttonWithType:UIButtonTypeInfoDark];

    UIButton*button = [[UIButtonalloc]initWithFrame:CGRectMake(20,50,80,80)];

    //frame表明了控件的坐标和宽高(CGRect类型)

    //[button setTitle:@"阿陶" forState:UIControlStateNormal];

    UIImage*image = [UIImageimageNamed:@"left_normal"];

    //根据名字加载图片

    [buttonsetBackgroundImage:imageforState:UIControlStateNormal];

    //给按钮设置背景图片

    //button.backgroundColor = [UIColor redColor];

    //按钮的监听

    [buttonaddTarget:selfaction:@selector(btnClickLister)forControlEvents:UIControlEventTouchUpInside];

    //添加到视图上面

    [self.viewaddSubview:button];

    //相框UIImageView

    UIImageView*imageview = [[UIImageViewalloc]initWithFrame:CGRectMake(150,50,200,200)];

    UIImage*image1 = [UIImageimageNamed:@"biaoqingdi"];

    //设置imageView显示的图片

    imageview.image= image1;

    [self.viewaddSubview:imageview];

    //标签UILabel

    UILabel*label = [[UILabelalloc]initWithFrame:CGRectMake(150,270,150,30)];

    //设置标签文本

    label.text=@"涛哥哥";

    //设置居中方式

    label.textAlignment=NSTextAlignmentCenter;

    label.textColor= [UIColorredColor];

    [self.viewaddSubview:label];}

    @end

    0","07�����p

    相关文章

      网友评论

          本文标题:ios学习笔记之ui按钮

          本文链接:https://www.haomeiwen.com/subject/kcsjjttx.html