のボタンの右側にチェックマークを追加する方法を理解しようとしていますUIActionSheet
。
AirPlayアクションシートのチェックマークを真似したいです。私が読んだことによると、これらのボタンをカスタマイズすると、Apple のプライベート API にアクセスすることになり、App Store で拒否される危険にさらされます。
このチェックマークを追加する安全な方法はありますか?
のボタンの右側にチェックマークを追加する方法を理解しようとしていますUIActionSheet
。
AirPlayアクションシートのチェックマークを真似したいです。私が読んだことによると、これらのボタンをカスタマイズすると、Apple のプライベート API にアクセスすることになり、App Store で拒否される危険にさらされます。
このチェックマークを追加する安全な方法はありますか?
この方法はどうですか?
ボタンの内側に「目盛り」が付いたラベルを配置し、それを切り替えます。以下は、まさにそれを行うためのコードです。切り替えは 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"];
}
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];