12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- //
- // UIView+BYIBInspectable.m
- // Prophet
- //
- // Created by Even on 17/3/27.
- // Copyright © 2017年 Even. All rights reserved.
- //
- #import "UIView+BYIBInspectable.h"
- @implementation UIView (BYIBInspectable)
- - (void)setCornerRadius:(NSInteger)cornerRadius{
- self.layer.cornerRadius = cornerRadius;
- self.layer.masksToBounds = cornerRadius > 0;
- }
- - (NSInteger)cornerRadius{
- return self.layer.cornerRadius;
- }
- - (void)setBorderWidth:(NSInteger)borderWidth{
- self.layer.borderWidth = borderWidth;
- }
- - (NSInteger)borderWidth{
- return self.layer.borderWidth;
- }
- - (void)setBorderColor:(UIColor *)borderColor{
- self.layer.borderColor = borderColor.CGColor;
- }
- - (UIColor *)borderColor{
- return [UIColor colorWithCGColor:self.layer.borderColor];
- }
- #pragma mark - hexRgbColor
- - (void)setHexRgbColor:(NSString *)hexRgbColor{
- NSScanner *scanner = [NSScanner scannerWithString:hexRgbColor];
- unsigned hexNum;
- if (![scanner scanHexInt:&hexNum]) return;
- self.backgroundColor = [self colorWithRGBHex:hexNum];
- }
- - (UIColor *)colorWithRGBHex:(UInt32)hex {
- int r = (hex >> 16) & 0xFF;
- int g = (hex >> 8) & 0xFF;
- int b = (hex) & 0xFF;
-
- return [UIColor colorWithRed:r / 255.0f
- green:g / 255.0f
- blue:b / 255.0f
- alpha:1.0f];
- }
- - (NSString *)hexRgbColor{
- return @"0xffffff";
- }
- - (void)setOnePx:(BOOL)onePx{
- if (onePx) {
- CGRect rect = self.frame;
- rect.size.height = 1.0 / [UIScreen mainScreen].scale;
- self.frame = rect;
- }
- }
- - (BOOL)onePx{
- return self.onePx;
- }
- @end
|