I set colors of the UITextField:
textField.backgroundColor = [UIColor whiteColor];
textField.textColor = [UIColor blackColor];
textField.alpha = 0.5f;
Alpha channel is set for bouth bkg and text colors.
How to set alpha separately for text color?
textField.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
try set textColor alpha.
Related
How to set a gradient color to UITextField cursor? The effect is just like the picture below:
here is the picture
you can ask disigner for an one pix picture ,then do like as follows:
UIColor *collor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"one"]];
self.textfield.tintColor = collor;
To change UITextField Cursor color, you have set it as Tint Color of Type UIColor.
textField.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"gradient"]];
Do this for all text fields in your app using the UITextField appearance proxy:
[[UITextField appearance] setTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"gradient"]]];
BONUS:
If you need to set gradient color for UIView:
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = view.bounds;
gradient.colors = #[(id)[UIColor whiteColor].CGColor, (id)[UIColor blackColor].CGColor];
[view.layer insertSublayer:gradient atIndex:0];
I am trying to change the background color of UIButton to a custom color. All the default greycolor, bluecolor, etc do not suffice.
UIColor *myColor=[UIColor colorWithRed:1 green:1 blue:0 alpha:1.0f];
_button.backgroundColor = [UIColor myColor];
It gives error on 2nd line saying
No known class method for selector 'myColor'
your code is fine, the simple mistake is again you creted the [UIColor property] on second line
UIColor *myColor=[UIColor colorWithRed:1 green:1 blue:0 alpha:1.0f];
Not like
_button.backgroundColor = [UIColor myColor];
Do like
_button.backgroundColor = myColor;
Update
you can directly use the color property like
_button.backgroundColor = [UIColor colorWithRed:1 green:1 blue:0 alpha:1.0f];
just change your current code with below code
UIColor *myColor=[UIColor colorWithRed:1 green:1 blue:0 alpha:1.0f];
_button.backgroundColor = myColor; // because myColor is UIColor
Try this:
UIColor *myColor=[UIColor colorWithRed:1 green:1 blue:0 alpha:1.0f];
_button.backgroundColor = myColor;
myColor is not defined in UIColor. It's a variable that you defined.
It's much more convenient to use:
_button.backgroundColor = [UIColor colorWithRed:1.0/255.0 green:1.0/255.0 blue:0.0/255.0 alpha:1.0f];
I'm implementing a UINavigationBar with some text on it but I want to change the font in the UINavigationBar text any of you knows if is posible to change font in the text programmatically?
I'll really appreciate your help
From iOS 7 and later:
NSShadow* shadow = [NSShadow new];
shadow.shadowOffset = CGSizeMake(0.0f, 1.0f);
shadow.shadowColor = [UIColor redColor];
[[UINavigationBar appearance] setTitleTextAttributes: #{
NSForegroundColorAttributeName: [UIColor greenColor],
NSFontAttributeName: [UIFont fontWithName:#"Helvetica" size:20.0f],
NSShadowAttributeName: shadow
}];
I am setting the Background color of my uitableviewCell like
cell.contentView.backgroundColor = [UIColor colorWithRed:8.0 green:210.0 blue:11.0 alpha:1.0];
its not working, however, if i do like
cell.contentView.backgroundColor = [UIColor grayColor];
it works then. Any help
UIColor has to be defined between 0 and 1 to get the RGB value to work (UIColor class reference):
cell.contentView.backgroundColor = [UIColor colorWithRed:8.0f/255.0f green:210.0f/255.0f blue:11.0f/255.0f alpha:1.0f];
I would like to make the text in my UILabel called coloursLabel change text colour by itself. I have tried the following method as another SO answer suggested (albeit for the backgroundColor) but it still doesn't change. Am I missing something silly?
UILabel *coloursLabel = [[UILabel alloc] init];
coloursLabel.text = #"This sentence is colourful!";
[coloursLabel sizeToFit];
coloursLabel.center = self.view.center;
coloursLabel.frame = CGRectOffset(coloursLabel.frame, timeForPage(6), 0);
[UIView animateWithDuration:2.0 animations:^{
coloursLabel.textColor = [UIColor greenColor];
coloursLabel.textColor = [UIColor redColor];
coloursLabel.textColor = [UIColor blueColor];
coloursLabel.textColor = [UIColor yellowColor];
coloursLabel.textColor = [UIColor blackColor];
} completion:NULL];
coloursLabel shows the correct text but the text is in black.
Any help would be much appreciated!
UILabel's textColor is not animatable. You could write your own Label class, using a CATextLayer as mask and animate its layer's backgroundColor.