2016-12-05 56 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]; 
    }); 
}