我想弄清楚如何在UIActionSheet
的按钮右侧添加复选标记。
我想模仿AirPlay活动表中的复选标记。根据我一直在阅读的内容,自定义这些按钮意味着访问Apple的私有API并使您有可能在App Store中被拒绝。
是否有安全的方法来添加此复选标记?
答案 0 :(得分:3)
这种方法怎么样?
在按钮内放置一个带有“勾号”的标签并切换。下面是一些代码来做到这一点。切换是通过KVO完成的,但可以用更简单的方式完成......
按钮在IB中通过self.theButton
- (void)viewDidLoad
{
[super viewDidLoad];
// Create a 'tick' label
CGRect rect;
rect.size = CGSizeMake(17, 21);
rect.origin.x = self.theButton.frame.size.width-17-10;
rect.origin.y = (self.theButton.frame.size.height-21)/2;
UILabel *label = [[UILabel alloc] initWithFrame:rect];
label.text = [NSString stringWithCString:"\342\234\223" encoding:NSUTF8StringEncoding];
label.backgroundColor = [UIColor clearColor];
label.hidden = YES;
// Put label inside the button
[self.theButton addSubview:label];
// Connect a observer on 'highlighted' (eq pressed basically)
// could use another method to track 'selected'
[self.theButton addObserver:self
forKeyPath:@"highlighted"
options:0
context:(__bridge void*)label];
}
// Toggle the 'tick' label
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(UIButton*)button
change:(NSDictionary *)change
context:(UILabel *)label
{
if (button.highlighted)
label.hidden = !label.hidden;
}
// Don't forget to cleanup
- (void)dealloc
{
[self.theButton removeObserver:self forKeyPath:@"highlighted"];
}
答案 1 :(得分:0)
NSString* strUrl=[MLControl shared].currentServerUrl;
for( MLServerUrl *title in [MLControl shared].arrServerUrl) {
NSString* strShow=title.name;
if ([strUrl isEqualToString: title.url]) {
strShow=[NSString stringWithFormat:@"√ %@",strShow];
}else{
strShow=[NSString stringWithFormat:@" %@",strShow];
}
[chooseImageSheet addButtonWithTitle:strShow];
}
// [[[chooseImageSheet valueForKey:@"_buttons"] objectAtIndex:0] setImage:[UIImage imageNamed:@"ic_check_black_18dp.png"] forState:UIControlStateNormal];
chooseImageSheet.actionSheetStyle = UIActionSheetStyleDefault;
[chooseImageSheet showFromRect:btnRc inView:sender animated:YES];