Objective c 目标C下拉菜单如何更改属性标题?
我是iOS编程的新手。今天,我在中下载并使用MKDropdownMenu 我无法更改导航栏中MKDropdownMenu的标题。我希望当用户更改所选行时,此文本将被更改Objective c 目标C下拉菜单如何更改属性标题?,objective-c,drop-down-menu,Objective C,Drop Down Menu,我是iOS编程的新手。今天,我在中下载并使用MKDropdownMenu 我无法更改导航栏中MKDropdownMenu的标题。我希望当用户更改所选行时,此文本将被更改 请帮帮我!谢谢 首先,声明一个NSString属性@property(强,非原子)NSString*navTitle 将默认导航标题设置为-(void)viewDidLoad类似 _navTitle=@“MKDropdownMenu” 更改-(NSAttributedString*)下拉菜单:(MKDropdownMenu*)下
请帮帮我!谢谢 首先,声明一个NSString属性
@property(强,非原子)NSString*navTitle代码>
将默认导航标题设置为-(void)viewDidLoad
类似
_navTitle=@“MKDropdownMenu”
更改-(NSAttributedString*)下拉菜单:(MKDropdownMenu*)下拉菜单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 {
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];
});
}
然后更改-(void)dropdown菜单:(mkdropdown菜单*)dropdown菜单didSelectRow:(NSInteger)row inComponent:(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 {
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];
});
}
首先,声明一个NSString属性@property(强,非原子)NSString*navTitle代码>
将默认导航标题设置为-(void)viewDidLoad
类似
_navTitle=@“MKDropdownMenu”
更改-(NSAttributedString*)下拉菜单:(MKDropdownMenu*)下拉菜单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 {
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];
});
}
然后更改-(void)dropdown菜单:(mkdropdown菜单*)dropdown菜单didSelectRow:(NSInteger)row inComponent:(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 {
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];
});
}