[ios] Added runtime attributes support.

This commit is contained in:
Ilya Grechuhin 2015-07-13 13:50:19 +03:00 committed by Alex Zolotarev
parent 2495eefe4a
commit 359bd80a12
14 changed files with 186 additions and 38 deletions

View file

@ -7,6 +7,7 @@
//
#import "CALayer+RuntimeAttributes.h"
#import "UIColor+MapsMeColor.h"
@implementation CALayer (RuntimeAttributes)
@ -20,13 +21,24 @@
return [UIColor colorWithCGColor:self.borderColor];
}
- (void)setBorderColorName:(NSString *)colorName
{
self.borderColor = [UIColor colorWithName:colorName].CGColor;
}
- (void)setShadowUIColor:(UIColor *)shadowUIColor {
- (void)setShadowUIColor:(UIColor *)shadowUIColor
{
self.shadowColor = shadowUIColor.CGColor;
}
- (UIColor *)shadowUIColor {
- (UIColor *)shadowUIColor
{
return [UIColor colorWithCGColor:self.shadowColor];
}
- (void)setShadowColorName:(NSString *)colorName
{
self.shadowColor = [UIColor colorWithName:colorName].CGColor;
}
@end

View file

@ -104,4 +104,10 @@ typedef void (^UIAlertViewCompletionBlock) (UIAlertView * alertView, NSInteger b
- (BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;
@end
@interface UIImage (ImageWithColor)
+ (UIImage *)imageWithColor:(UIColor *)color;
@end

View file

@ -414,3 +414,23 @@ static const void * UIAlertViewShouldEnableFirstOtherButtonBlockKey = & UIAlert
}
@end
@implementation UIImage (ImageWithColor)
+ (UIImage *)imageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0, 0.0, 1.0, 1.0);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end

View file

@ -15,6 +15,8 @@
28AD73880D9D96C1002E5188 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD73870D9D96C1002E5188 /* MainWindow.xib */; };
340F24631B14910500F874CD /* RouteState.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340F24621B14910500F874CD /* RouteState.mm */; };
34287FDC1B3D7C4800F9959C /* libFlurry_6.4.0.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 34287FDB1B3D7C4800F9959C /* libFlurry_6.4.0.a */; };
342AD76F1B53D30C00E0B997 /* UIButton+RuntimeAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = 342AD76E1B53D30C00E0B997 /* UIButton+RuntimeAttributes.m */; };
342AD7721B53D32F00E0B997 /* UIView+RuntimeAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = 342AD7711B53D32F00E0B997 /* UIView+RuntimeAttributes.m */; };
343F262E1AEFC4A300388A6D /* MWMFrameworkUtils.mm in Sources */ = {isa = PBXBuildFile; fileRef = 343F262D1AEFC4A300388A6D /* MWMFrameworkUtils.mm */; };
343F26301AEFDB1A00388A6D /* Framework.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 343F262F1AEFDB1A00388A6D /* Framework.cpp */; };
343F26311AEFDF3E00388A6D /* resources-xhdpi in Resources */ = {isa = PBXBuildFile; fileRef = 97FC99DA19C1A2CD00C1CF98 /* resources-xhdpi */; };
@ -342,6 +344,10 @@
340F24621B14910500F874CD /* RouteState.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RouteState.mm; sourceTree = "<group>"; };
340F24641B15F01D00F874CD /* MWMSideMenuDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMSideMenuDelegate.h; sourceTree = "<group>"; };
34287FDB1B3D7C4800F9959C /* libFlurry_6.4.0.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libFlurry_6.4.0.a; path = Statistics/libFlurry_6.4.0.a; sourceTree = "<group>"; };
342AD76D1B53D30C00E0B997 /* UIButton+RuntimeAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIButton+RuntimeAttributes.h"; sourceTree = "<group>"; };
342AD76E1B53D30C00E0B997 /* UIButton+RuntimeAttributes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIButton+RuntimeAttributes.m"; sourceTree = "<group>"; };
342AD7701B53D32F00E0B997 /* UIView+RuntimeAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+RuntimeAttributes.h"; sourceTree = "<group>"; };
342AD7711B53D32F00E0B997 /* UIView+RuntimeAttributes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+RuntimeAttributes.m"; sourceTree = "<group>"; };
342E75A11B302FCC00A8635F /* MWMPlacePageViewManagerDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMPlacePageViewManagerDelegate.h; sourceTree = "<group>"; };
343F262C1AEFC4A300388A6D /* MWMFrameworkUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMFrameworkUtils.h; sourceTree = "<group>"; };
343F262D1AEFC4A300388A6D /* MWMFrameworkUtils.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMFrameworkUtils.mm; sourceTree = "<group>"; };
@ -1130,6 +1136,10 @@
974726401832306C006B7CB7 /* Categories */ = {
isa = PBXGroup;
children = (
342AD7701B53D32F00E0B997 /* UIView+RuntimeAttributes.h */,
342AD7711B53D32F00E0B997 /* UIView+RuntimeAttributes.m */,
342AD76D1B53D30C00E0B997 /* UIButton+RuntimeAttributes.h */,
342AD76E1B53D30C00E0B997 /* UIButton+RuntimeAttributes.m */,
9747264218323080006B7CB7 /* UIKitCategories.h */,
9747264118323080006B7CB7 /* UIKitCategories.m */,
B08AA8D81A26299A00810B1C /* TimeUtils.h */,
@ -2170,6 +2180,7 @@
F6F533A31B3C248900C1940B /* UIColor+MapsMeColor.mm in Sources */,
CB252D6F16FF82C9001E41E9 /* Statistics.mm in Sources */,
978F9244183B660F000D6C7C /* SwitchCell.m in Sources */,
342AD7721B53D32F00E0B997 /* UIView+RuntimeAttributes.m in Sources */,
97508423199522D300A7457D /* SettingsAndMoreVC.mm in Sources */,
F6ED13541B1643900095C6DE /* MWMDirectionView.mm in Sources */,
34BC72271B0DECAE0012A34B /* MWMSideMenuView.mm in Sources */,
@ -2179,6 +2190,7 @@
976D86EC19C8697700C920EF /* ProgressView.m in Sources */,
B0FBFA271A515AFD0086819E /* ViewController.m in Sources */,
3472EC051B4D44BE0085CB79 /* UIFont+MapsMeFonts.mm in Sources */,
342AD76F1B53D30C00E0B997 /* UIButton+RuntimeAttributes.m in Sources */,
F63732961AE9431E00A03764 /* MWMBasePlacePageView.mm in Sources */,
97A8001018B21395000C07A2 /* SearchBar.mm in Sources */,
EDC5C543175F2CA600420E92 /* ShareActionSheet.mm in Sources */,

View file

@ -0,0 +1,17 @@
//
// UIButton+RuntimeAttributes.h
// Maps
//
// Created by Ilya Grechuhin on 09.07.15.
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIButton (RuntimeAttributes)
@property (nonatomic) NSString * localizedText;
- (void)setBackgroundColor:(UIColor *)color forState:(UIControlState)state;
@end

View file

@ -0,0 +1,55 @@
//
// UIButton+RuntimeAttributes.m
// Maps
//
// Created by Ilya Grechuhin on 09.07.15.
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
#import "Macros.h"
#import "UIButton+RuntimeAttributes.h"
#import "UIColor+MapsMeColor.h"
#import "UIFont+MapsMeFonts.h"
#import "UIKitCategories.h"
@implementation UIButton (RuntimeAttributes)
- (void)setLocalizedText:(NSString *)localizedText {
[self setTitle:L(localizedText) forState:UIControlStateNormal];
}
- (NSString *)localizedText {
return L([self titleForState:UIControlStateNormal]);
}
- (void)setFontName:(NSString *)fontName
{
self.titleLabel.font = [UIFont fontWithName:fontName];
}
- (void)setTextColorName:(NSString *)colorName
{
[self setTitleColor:[UIColor colorWithName:colorName] forState:UIControlStateNormal];
}
- (void)setTextColorHighlightedName:(NSString *)colorName
{
[self setTitleColor:[UIColor colorWithName:colorName] forState:UIControlStateHighlighted];
}
- (void)setBackgroundColorName:(NSString *)colorName
{
[self setBackgroundColor:[UIColor colorWithName:colorName] forState:UIControlStateNormal];
}
- (void)setBackgroundHighlightedColorName:(NSString *)colorName
{
[self setBackgroundColor:[UIColor colorWithName:colorName] forState:UIControlStateHighlighted];
}
- (void)setBackgroundColor:(UIColor *)color forState:(UIControlState)state
{
[self setBackgroundImage:[UIImage imageWithColor:color] forState:state];
}
@end

View file

@ -27,4 +27,6 @@
+ (UIColor *)whiteHintText;
+ (UIColor *)whiteDividers;
+ (UIColor *)colorWithName:(NSString *)colorName;
@end

View file

@ -103,6 +103,14 @@ static CGFloat const alpha100 = 1.;
return [[UIColor whiteColor] colorWithAlphaComponent:alpha12];
}
+ (UIColor *)colorWithName:(NSString *)colorName
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
return [[UIColor class] performSelector:NSSelectorFromString(colorName)];
#pragma clang diagnostic pop
}
CGFloat scaled(CGFloat f)
{
return f / 255.;

View file

@ -23,4 +23,6 @@
+ (UIFont *)bold16;
+ (UIFont *)bold48;
+ (UIFont *)fontWithName:(NSString *)fontName;
@end

View file

@ -70,4 +70,12 @@
return [UIFont fontWithName:@"HelveticaNeue-Bold" size:48];
}
+ (UIFont *)fontWithName:(NSString *)fontName
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
return [[UIFont class] performSelector:NSSelectorFromString(fontName)];
#pragma clang diagnostic pop
}
@end

View file

@ -10,17 +10,13 @@
#import "MWMTextView.h"
@interface UILabel (RuntimeAttributes)
@property (copy, nonatomic) NSString * localizedText;
@end
@interface UIButton (RuntimeAttributes)
@property (copy, nonatomic) NSString * localizedText;
@property (nonatomic) NSString * localizedText;
@end
@interface MWMTextView (RuntimeAttributes)
@property (copy, nonatomic) NSString * localizedPlaceholder;
@property (nonatomic) NSString * localizedPlaceholder;
@end
@interface UITextField (RuntimeAttributes)
@property (copy, nonatomic) NSString * localizedPlaceholder;
@property (nonatomic) NSString * localizedPlaceholder;
@end

View file

@ -8,6 +8,8 @@
#import "UILabel+RuntimeAttributes.h"
#import "UIKitCategories.h"
#import "UIFont+MapsMeFonts.h"
#import "UIColor+MapsMeColor.h"
// Runtime attributes for setting localized text in Xib.
@ -23,30 +25,12 @@
- (void)setFontName:(NSString *)fontName
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
self.font = [[UIFont class] performSelector:NSSelectorFromString(fontName)];
#pragma clang diagnostic pop
self.font = [UIFont fontWithName:fontName];
}
@end
@implementation UIButton (RuntimeAttributes)
- (void)setLocalizedText:(NSString *)localizedText {
[self setTitle:L(localizedText) forState:UIControlStateNormal];
}
- (NSString *)localizedText {
return L([self titleForState:UIControlStateNormal]);
}
- (void)setFontName:(NSString *)fontName
- (void)setColorName:(NSString *)colorName
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
self.titleLabel.font = [[UIFont class] performSelector:NSSelectorFromString(fontName)];
#pragma clang diagnostic pop
self.textColor = [UIColor colorWithName:colorName];
}
@end
@ -65,10 +49,7 @@
- (void)setFontName:(NSString *)fontName
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
self.font = [[UIFont class] performSelector:NSSelectorFromString(fontName)];
#pragma clang diagnostic pop
self.font = [UIFont fontWithName:fontName];
}
@end
@ -87,10 +68,7 @@
- (void)setFontName:(NSString *)fontName
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
self.font = [[UIFont class] performSelector:NSSelectorFromString(fontName)];
#pragma clang diagnostic pop
self.font = [UIFont fontWithName:fontName];
}
@end

View file

@ -0,0 +1,13 @@
//
// UIView+RuntimeAttributes.h
// Maps
//
// Created by Ilya Grechuhin on 09.07.15.
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIView (RuntimeAttributes)
@end

View file

@ -0,0 +1,19 @@
//
// UIView+RuntimeAttributes.m
// Maps
//
// Created by Ilya Grechuhin on 09.07.15.
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
#import "UIColor+MapsMeColor.h"
#import "UIView+RuntimeAttributes.h"
@implementation UIView (RuntimeAttributes)
- (void)setBackgroundColorName:(NSString *)colorName
{
self.backgroundColor = [UIColor colorWithName:colorName];
}
@end