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