Getting default UI colors on iPhone

Here is my iPhone project with a XIB file with a regular UIButton on it. The button has a text color - a beautiful shade of blue, RGB (50, 79, 133) to be precise.

Is there a quick and correct way to get this color value at runtime? Not the color of this particular button, but the default text color for UIButtons? Preferably as UIColor *or CGColorRef.

Is there an idea of ​​the system colors on the iPhone, or is it just the default set by presets in Interface Builder?

Yes, I can do basic math and convert RGB to a floating point representation (UGH!) That uses UIColor. Anything more elegant than that?

+3
source share
2

UIColor UIColor, :

UIColor + Extras.h

#import <UIKit/UIKit.h>

@interface UIColor(Extras)
+ (UIColor *)colorWithRGBA:(NSUInteger) rgba;
+ (UIColor *)colorWithRGB:(NSUInteger) rgb;
@end

UIColor + Extras.m

#import "UIColor+Extras.h"

@implementation UIColor(Extras)
+ (UIColor *)colorWithRGBA:(NSUInteger) rgba
{
    return [UIColor colorWithRed:(rgba >> 24) / 255.0f green:(0xff & ( rgba >> 16)) / 255.0f blue:(0xff & ( rgba >> 8)) / 255.0f alpha:(0xff & rgba) / 255.0f];
}

+ (UIColor *)colorWithRGB:(NSUInteger) rgb
{
    return [UIColor colorWithRed:(rgb >> 16) / 255.0f green:(0xff & ( rgb >> 8)) / 255.0f blue:(0xff & rgb) / 255.0f alpha:1.0];
}
@end

, [UIColor colorWithRGBA:0xFF00FFFF] [UIColor colorWithRGB:0xFF00FF]

, , UIButton.h, , UIColor, [UIColor lightTextColor] [UIColor darkTextColor] .. UIColor.

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIColor_Class/Reference/Reference.html

, :

[[button titleLabel] textColor]

. , . .

+2

, , , :

label.textColor = [button titleColorForState: UIControlStateNormal];

, UIControlState.

+2

Source: https://habr.com/ru/post/1792623/


All Articles