我是iOS編程的新手。今天我下載並使用MKDropdownMenu https://github.com/maxkonovalov/MKDropdownMenu目標C MKDropdownMenu如何更改屬性標題?
我不能在導航欄中更改MKDropdownMenu的標題。我希望當用戶更改所選行時,此文本將被更改。
請幫幫我!謝謝!
我是iOS編程的新手。今天我下載並使用MKDropdownMenu https://github.com/maxkonovalov/MKDropdownMenu目標C MKDropdownMenu如何更改屬性標題?
我不能在導航欄中更改MKDropdownMenu的標題。我希望當用戶更改所選行時,此文本將被更改。
請幫幫我!謝謝!
首先,聲明的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];
});
}