我有一个 UIView 类别方法来调整 UIView 的框架:
-(void)setFrameWidth:(NSInteger)aWidth andHeight:(NSInteger)aHeight
{
CGRect labelFrame = self.frame;
labelFrame.size = CGSizeMake(aWidth, aHeight);
self.frame = labelFrame;
}
但是,当我将它应用于 UIRoundedRectButton 时:
//button for options
optionsButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[optionsButton setTitle:@"Options" forState:UIControlStateNormal];
[optionsButton addTarget:self action:@selector(goToOptions:) forControlEvents:UIControlEventTouchUpInside];
[optionsButton setFrameWidth:200 andHeight:50];
optionsButton.center = CGPointMake(SCREEN_X_LENGTH_HALF, SCREEN_Y_LENGTH_TWO_THIRDS);
[self.view addSubview:optionsButton];
它抱怨说'-[UIRoundedRectButton setFrameWidth:andHeight:]: unrecognized selector sent to instance 0x718a600'。
如何让我的类别方法在按钮上工作?