【发布时间】:2011-07-19 01:33:36
【问题描述】:
我有一个使用图像进行显示的 UIButton。
问题是我的图像是 109x78,但我希望按钮的大小为 109x20,固定在左上角并剪切所有大于 20 像素高的东西。
这就是我现在拥有的:
UIButton *startTrainingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[startTrainingBtn setContentMode:UIViewContentModeTopLeft];
[startTrainingBtn setClipsToBounds:YES];
[startTrainingBtn setImage:[UIImage imageNamed:@"startTrainingClosed"] forState:UIControlStateNormal];
[startTrainingBtn setFrame:CGRectMake(900, 653, 109, 20)];
[self.view addSubview:startTrainingBtn];
我原以为将 ContentMode 设置为 TopLeft 并将 ClipsToBounds 设置为 YES 会起作用,但它只是缩小图像以适应。
【问题讨论】:
标签: ios cocoa-touch uibutton