objective c - How do I change the color of the text in a UIPickerView under iOS 7? -


i'm aware of pickerview:viewforrow:forcomponent:reusingview method, when using view passes in reusingview: how change use different text color? if use view.backgroundcolor = [uicolor whitecolor]; none of views show anymore.

there function in delegate method more elegant:

- (nsattributedstring *)pickerview:(uipickerview *)pickerview attributedtitleforrow:(nsinteger)row forcomponent:(nsinteger)component {     nsstring *title = @"sample title";     nsattributedstring *attstring =          [[nsattributedstring alloc] initwithstring:title attributes:@{nsforegroundcolorattributename:[uicolor whitecolor]}];      return attstring; } 

if want change selection bar colors well, found had add 2 separate uiviews view containing uipickerview, spaced 35 pts apart picker height of 180.

update swift 3:

func pickerview(_ pickerview: uipickerview, attributedtitleforrow row: int, forcomponent component: int) -> nsattributedstring? {      let string = "mystring"     return nsattributedstring(string: string, attributes: [nsforegroundcolorattributename:uicolor.white]) } 

remember when use method: don't need implement titleforrowincomponent() never called when using attributedtitleforrow().


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -