{"rsdb":{"rid":"407346","subhead":"","postdate":"0","aid":"281605","fid":"99","uid":"1","topic":"1","content":"
\n
\n

\u7075\u611f\u6765\u6e90\u4e8e\u524d\u7aefCSS\u753b\u7ea2\u5fc3\u7684\u539f\u7406 \u53c2\u8003<\/a><\/p> \n <\/blockquote> \n

\"\u793a\u4f8b\"<\/p> \n

\u4e0a\u4ee3\u7801<\/h1> \n
\n#import <UIKit\/UIKit.h>\n\/**\n    \u7075\u611f\u6765\u81ea\u4e8e\u524d\u7aefCSS\u753b\u7ea2\u5fc3\u7684\u539f\u7406: \u4e00\u4e2a\u6b63\u65b9\u5f62 + \u4e24\u4e2a\u5706 + \u6574\u4f53\u65cb\u8f6c\u4e00\u5b9a\u7684\u89d2\u5ea6\n*\/\n\nNS_ASSUME_NONNULL_BEGIN\nIB_DESIGNABLE\n@interface WGBHeartView : UIView\n\/\/?\u5fc3\u6709\u591a\u5927?\n@property (nonatomic,assign) IBInspectable CGFloat heartSize;\n\/\/?\u5fc3\u7684\u989c\u8272?\n@property (nonatomic,strong) IBInspectable UIColor *heartColor;\n@end\nNS_ASSUME_NONNULL_END\n\n\n#import "WGBHeartView.h"\n\n@interface WGBHeartView()\n\n@property (nonatomic,strong) UIView *bottomView;\n@property (nonatomic,strong) UIView *leftView;\n@property (nonatomic,strong) UIView *rightView;\n\n@end\n\n@implementation WGBHeartView\n\n- (instancetype)initWithFrame:(CGRect)frame\n{\n    self = [super initWithFrame:frame];\n    if (self) {\n        [self initConfig];\n    }\n    return self;\n}\n\n- (instancetype)initWithCoder:(NSCoder *)coder\n{\n    self = [super initWithCoder:coder];\n    if (self) {\n        [self initConfig];\n    }\n    return self;\n}\n\n- (void)initConfig{\n        \/\/\u9ed8\u8ba4\u503c\n    self.heartSize = 150.0;\n    self.heartColor = [UIColor redColor];\n    [self addSubview: self.bottomView];\n    [self addSubview: self.leftView];\n    [self addSubview: self.rightView];\n    \/\/\u63d0\u524d\u65cb\u8f6c45\u5ea6\n    self.transform = CGAffineTransformMakeRotation(M_PI_4);\n}\n\n\/\/\u53bb\u9664\u8bbe\u7f6e\u80cc\u666f\u8272 \n- (void)setBackgroundColor:(UIColor *)backgroundColor{\n    backgroundColor = [UIColor clearColor];\n    [super setBackgroundColor:backgroundColor];\n}\n\n- (void)setHeartSize:(CGFloat)heartSize{\n    _heartSize = heartSize;\n    CGFloat partSize = heartSize\/3.0;\n    self.bottomView.frame = CGRectMake(partSize, partSize, partSize*2 , partSize*2);\n    self.leftView.frame = CGRectMake(0, partSize, partSize*2 , partSize*2);\n    self.rightView.frame = CGRectMake(partSize, 0, partSize*2 , partSize*2);\n    \n    self.leftView.layer.cornerRadius = partSize;\n    self.rightView.layer.cornerRadius = partSize;\n}\n\n- (void)setHeartColor:(UIColor *)heartColor{\n    _heartColor = heartColor;\n    self.bottomView.backgroundColor = heartColor;\n    self.leftView.backgroundColor = heartColor;\n    self.rightView.backgroundColor = heartColor;\n}\n\n    \/\/\/MARK:- lazy load\n- (UIView *)bottomView{\n    if (!_bottomView) {\n        _bottomView = [[UIView alloc] initWithFrame:CGRectZero];\n        [self addSubview:_bottomView];\n    }\n    return _bottomView;\n}\n- (UIView *)leftView{\n    if (!_leftView) {\n        _leftView = [[UIView alloc] initWithFrame:CGRectZero];\n        [self addSubview:_leftView];\n    }\n    return _leftView;\n}\n\n- (UIView *)rightView{\n    if (!_rightView) {\n        _rightView = [[UIView alloc] initWithFrame:CGRectZero];\n        [self addSubview:_rightView];\n    }\n    return _rightView;\n}\n\n@end\n\n<\/code><\/pre> \n 

\"IB\"<\/p> \n

\u7b80\u5355\u8c03\u7528\u5982\u4e0b:<\/h1> \n
    WGBHeartView *heartView = [[WGBHeartView alloc] initWithFrame:CGRectMake(100, 100, 100 , 100)];\n    heartView.heartColor = [UIColor blackColor];\/\/\u9ed8\u8ba4\u989c\u8272\u662f\u7ea2\u8272\n    heartView.heartSize = 100; \/\/\u8fd9\u4e2a\u5c3a\u5bf8\u6700\u597d\u662f\u8bbe\u7f6e\u4e0e\u89c6\u56fe\u5bbd\u9ad8\u4e00\u81f4 \u751f\u6210\u7684\u7231\u5fc3??\u6bd4\u8f83\u89c4\u5219\n    [self.view addSubview: heartView];\n    \n    for (NSInteger i = 0; i < 6; i += 1) {\n        CGFloat heartWH = 50.0f;\n        CGFloat margin = 15.0f;\n        WGBHeartView *heartItemView = [[WGBHeartView alloc] initWithFrame:CGRectMake(20 + (heartWH+margin)*i,   250, heartWH , heartWH)];\n        heartItemView.heartColor = [UIColor colorWithRed:arc4random()%256\/255.0f green:arc4random()%256\/255.0f  blue:arc4random()%256\/255.0f alpha:1.0f];\n        heartItemView.heartSize = heartWH;\n        [self.view addSubview: heartItemView];\n    }\n\n<\/code><\/pre> \n<\/div>","orderid":"0","title":"iOS\u5982\u4f55\u7b80\u5355\u5b9e\u73b0\u7ed8\u5236\u7231\u5fc3?","smalltitle":"","mid":"0","fname":"iOS","special_id":"0","bak_id":"0","info":"0","hits":"51","pages":"1","comments":"0","posttime":"2020-03-23 14:43:03","list":"1584945783","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"iOS<\/A> \u5982\u4f55<\/A> \u7b80\u5355<\/A> \u5b9e\u73b0<\/A> \u7ed8\u5236<\/A> \u7231\u5fc3<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"14.17.22.34","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"iOS\u5982\u4f55\u7b80\u5355\u5b9e\u73b0\u7ed8\u5236\u7231\u5fc3?","lastview":"1590357269","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}