Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 绘制自定义按钮_Iphone_Objective C_Cocoa Touch_Uibutton - Fatal编程技术网

Iphone 绘制自定义按钮

Iphone 绘制自定义按钮,iphone,objective-c,cocoa-touch,uibutton,Iphone,Objective C,Cocoa Touch,Uibutton,我正在绘制一个自定义按钮: UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom]; myButton.frame = CGRectMake(10,10,44,70); [myButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [myButton setTitle:@"Order" forState:UIControlStat

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

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

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

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

[myButton setBackgroundImage:someUIImageRef forState:UIControlStateNormal];
[myButton setBackgroundImage:someOtherUIImageRef forState:UIControlStateHighlighted];
对。 因为您使用的是自定义按钮,所以需要手动描述每个状态,否则它们将看起来像正常状态