2016-12-05 24 views

回答

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]; 
    }); 
}