目标C MKDropdownMenu如何更改属性标题?

时间:2016-12-05 08:19:29

标签: objective-c drop-down-menu

我是iOS编程的新手。今天我在https://github.com/maxkonovalov/MKDropdownMenu

下载并使用MKDropdownMenu

我无法在导航栏中更改MKDropdownMenu的标题。我希望当用户更改所选行时,此文本将被更改。

请帮帮我!谢谢!

1 个答案:

答案 0 :(得分:0)

首先,声明一个NSString属性@property (strong, nonatomic) NSString *navTitle;

将您的默认导航标题设置为- (void)viewDidLoad

_navTitle = @" MKDropdownMenu";

像这样改变- (NSAttributedString *)dropdownMenu:(MKDropdownMenu *)dropdownMenu attributedTitleForComponent:(NSInteger)component方法 -

- (NSAttributedString *)dropdownMenu:(MKDropdownMenu *)dropdownMenu attributedTitleForComponent:(NSInteger)component {

        return [[NSAttributedString alloc] initWithString:_navTitle
                                               attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:18 weight:UIFontWeightLight],
                                                            NSForegroundColorAttributeName: [UIColor whiteColor]}];
}

并像这样更改- (void)dropdownMenu:(MKDropdownMenu *)dropdownMenu didSelectRow:(NSInteger)row inComponent:(NSInteger)component -

- (void)dropdownMenu:(MKDropdownMenu *)dropdownMenu didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    NSString *colorString = self.colors[row];
    self.textLabel.text = colorString;
    _navTitle = colorString;

    [self.navigationItem setTitle:colorString];

    UIColor *color = UIColorWithHexString(colorString);
    self.view.backgroundColor = color;
    self.childViewController.shapeView.strokeColor = color;

    delay(0.15, ^{
        [dropdownMenu closeAllComponentsAnimated:YES];
        [dropdownMenu reloadAllComponents];
    });
}