【问题标题】:Drawing a custom button绘制自定义按钮
【发布时间】:2010-11-30 23:46:01
【问题描述】:

我正在绘制一个自定义按钮:

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
myButton.frame = CGRectMake(10,10,44,70);
[myButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[myButton setTitle:@"Order" forState:UIControlStateNormal];                   

当我点击按钮时,背景颜色不会改变。我是否需要为正常状态和选定状态使用不同的图像?这里有什么诀窍?

【问题讨论】:

    标签: iphone objective-c cocoa-touch uibutton


    【解决方案1】:

    是的,你需要为不同的状态使用不同的图像:

    [myButton setBackgroundImage:someUIImageRef forState:UIControlStateNormal];
    [myButton setBackgroundImage:someOtherUIImageRef forState:UIControlStateHighlighted];
    

    【讨论】:

      【解决方案2】:

      是的。 因为您使用的是自定义按钮,所以您需要手动描述每个状态,否则它们看起来就像正常状态。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-14
        • 2018-11-13
        • 1970-01-01
        • 2011-05-14
        • 1970-01-01
        相关资源
        最近更新 更多