怎样在代码里给按钮添加title?如何使添加的图片和按钮相匹配?能不能将按钮的title设置成变量?

解决方案 »

  1.   

    UIButton *setButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        //button坐标
        setButton.frame = CGRectMake(120, 120, 120, 120);
        //button上面子的颜色
        [setButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        //button上显示子名字
        [setButton setTitle:@"set" forState:UIControlStateNormal];
        //添加setbutton点击事件 更换lable的text
        [setButton addTarget:self action:@selector(lableSet) forControlEvents:UIControlEventTouchUpInside];
        //button添加到controller的view上,resbutton同理
        [self.view addSubview:setButton];只要你想改变TITLE 就可以使用 [setButton setTitle:@"set" forState:UIControlStateNormal];这句话其实在使用官方控件的时候都注意一下他都那些属性  他的属性名都写的很容易理解一看就懂了
    希望能帮到你哦~