我是iOS新手。我想在我的应用程序的顶部菜单上放一个“星形”按钮。有没有办法让iOS内置的星形按钮类似于UIBarButtonSystemItemAdd
如果没有,我怎样才能获得类似于Apple在iOS中使用的常见明星的图像?
与此类似:
答案 0 :(得分:1)
一种简单快捷的方法是使用FontawesomeKit 您可以轻松创建如下按钮:
FAKFontAwesome *icon = [FAKFontAwesome starIconWithSize:20];
[icon addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor]];
UIBarButtonItem *favButton = [[UIBarButtonItem alloc] initWithImage:[icon imageWithSize:CGSizeMake(20, 20)]
style:UIBarButtonItemStylePlain
target:self
action:@selector(doSomething:)];
答案 1 :(得分:0)
答案 2 :(得分:0)
跟随andreamazz所说的,这里的代码是在navBaritem(swift)中有一个彩色星(喜欢)按钮:
let favAwesome = FAKFontAwesome.starIconWithSize(30.0) as FAKFontAwesome
favAwesome.addAttribute(NSForegroundColorAttributeName, value: UIColor.whiteColor())
let favBtn = UIButton.buttonWithType(UIButtonType.System) as UIButton
favBtn.frame = CGRectMake(0,0,30,30)
favBtn.setImage(favAwesome.imageWithSize(CGSizeMake(30, 30)), forState: .Normal)
favBtn.addTarget(self, action: "favorite", forControlEvents: UIControlEvents.TouchUpInside)
// favBarBtn is a class instance so we can access in the action method
favBarBtn = UIBarButtonItem(customView: favBtn)
navigationItem.rightBarButtonItem = favBarBtn
// your custom code here to find isFavorite
if isFavorite {
favBtn.tintColor = UIColor.redColor()
} else {
favBtn.tintColor = UIColor.blueColor()
}
然后有“最喜欢的”方法来改变颜色(并设置/取消设置收藏夹):
func favorite() {
// your custom favoriting code here
let favBtn = favBarBtn?.customView as UIButton!
if isFavorite {
favBtn.tintColor = UIColor.redColor()
} else {
favBtn.tintColor = UIColor.blueColor()
}
}