按钮小结1

按钮这个空间我非常的讨厌,用代码写很恶心

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 50, 50);
//    button.center = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds));
    [button setTitle:@"转换转换转换" forState:UIControlStateNormal];
    [button setBackgroundColor:[UIColor whiteColor]];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(turnToAnotherController:) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:button];

这是一段简单示例,其中

设置title 只能用 setTitle: 方法

设置字体颜色也只能用对应方法 

button有个textlabel 那个是只读 设置任何都没用的

 

原文地址:https://www.cnblogs.com/qiqingnan/p/4433111.html