Creating a UIImage from a UIColor to use as a background image for UIButton [duplicate]

I created a category around UIButton to be able to set the background color of the button and set the state. You might find this useful. @implementation UIButton (ButtonMagic) – (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state { [self setBackgroundImage:[UIButton imageFromColor:backgroundColor] forState:state]; } + (UIImage *)imageFromColor:(UIColor *)color { CGRect rect = CGRectMake(0, 0, 1, 1); UIGraphicsBeginImageContext(rect.size); CGContextRef context = … Read more

UIButton: how to center an image and a text using imageEdgeInsets and titleEdgeInsets?

For what it’s worth, here’s a general solution to positioning the image centered above the text without using any magic numbers. Note that the following code is outdated and you should probably use one of the updated versions below: // the space between the image and text CGFloat spacing = 6.0; // lower the text … Read more

Label under image in UIButton

Or you can just use this category: ObjC @interface UIButton (VerticalLayout) – (void)centerVerticallyWithPadding:(float)padding; – (void)centerVertically; @end @implementation UIButton (VerticalLayout) – (void)centerVerticallyWithPadding:(float)padding { CGSize imageSize = self.imageView.frame.size; CGSize titleSize = self.titleLabel.frame.size; CGFloat totalHeight = (imageSize.height + titleSize.height + padding); self.imageEdgeInsets = UIEdgeInsetsMake(- (totalHeight – imageSize.height), 0.0f, 0.0f, – titleSize.width); self.titleEdgeInsets = UIEdgeInsetsMake(0.0f, – imageSize.width, – (totalHeight … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)