4

我试图弄清楚如何在UIActionSheet.

我想模仿 AirPlay 操作表中的复选标记。根据我一直在阅读的内容,自定义这些按钮意味着访问 Apple 的私有 API,并使您面临在 App Store 中被拒绝的风险。

有没有一种安全的方法来添加这个复选标记?

4

2 回答 2

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"];
}
于 2013-04-16T23:04:23.173 回答
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];
于 2014-12-18T06:06:10.863 回答