我新的iOS.And我面對關於改變字體真棒label.My代碼顏色的一個問題是這樣的如何改變字體顏色真棒上UINavigation酒吧目標C
UILabel *lab =[[UILabel alloc] init];
lab.text = [NSString awesomeIcon:FaChild];
UIImage *listImage2 = [UIImage imageNamed:@"Image.png"];
UIButton *listButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
listButton2.backgroundColor=[UIColor whiteColor];
[[listButton2 layer] setBorderWidth:0.5f];
listButton2.layer.borderColor =[[UIColor blackColor] CGColor];
listButton2.layer.cornerRadius = calenderbtn.bounds.size.width/3.4;// this value vary as per your desire
listButton2.clipsToBounds = YES;
UIFont *font = [UIFont fontWithName:@"FontAwesome" size:15.0];
UIColor *color = [UIColor whiteColor];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:font
forKey:NSFontAttributeName];
[NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,color,NSForegroundColorAttributeName, nil];
NSAttributedString *attributedStr = [[NSAttributedString alloc] initWithString:lab.text attributes:attrsDictionary];
// get the image size and apply it to the button frame
CGRect listButton2Frame = listButton2.frame;
listButton2Frame.size = listImage2.size;
listButton2.frame = listButton2Frame;
[listButton2 setAttributedTitle:attributedStr forState:UIControlStateNormal];
[listButton2 addTarget:self
action:@selector(LogoutClick:)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *jobsButton2 =
[[UIBarButtonItem alloc] initWithCustomView:listButton2];
它的輸出看起來像這樣 但它在背面顏色,但我寫白色colour.How代碼改變它的顏色。感謝Advace!
您是否確定'FontAwesome'在您的應用中可用?另外,你是否試圖在圖像上設置字體?你確定? – dirtydanee
@dirtydanee字體真棒是在我的應用程序,我設置UILabel上的字體真棒 – Muju
你想改變'listButton2'的背景顏色?你想它是黑色的? – dirtydanee