From e2b4617048bed5b2984652d91c0e7ea7ca4886f1 Mon Sep 17 00:00:00 2001 From: fengshuo <963787902@qq.com> Date: Mon, 28 Mar 2022 15:00:50 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=B0=8F=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=90=8D=E5=AD=97=E6=B8=90=E5=8F=98=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xplan-ios.xcodeproj/project.pbxproj | 6 ++ .../View/Cell/XPHomeLittleGameTableViewCell.m | 58 +++++++++---------- .../Home/View/SubViews/XPHomeGradientLabel.h | 17 ++++++ .../Home/View/SubViews/XPHomeGradientLabel.m | 43 ++++++++++++++ 4 files changed, 95 insertions(+), 29 deletions(-) create mode 100644 xplan-ios/Main/Home/View/SubViews/XPHomeGradientLabel.h create mode 100644 xplan-ios/Main/Home/View/SubViews/XPHomeGradientLabel.m diff --git a/xplan-ios.xcodeproj/project.pbxproj b/xplan-ios.xcodeproj/project.pbxproj index 5039960e..f923ce40 100644 --- a/xplan-ios.xcodeproj/project.pbxproj +++ b/xplan-ios.xcodeproj/project.pbxproj @@ -233,6 +233,7 @@ E81366F826F0C12A0076364C /* LoginFullInfoProtocol.h in Sources */ = {isa = PBXBuildFile; fileRef = E81366F726F0C0F60076364C /* LoginFullInfoProtocol.h */; }; E81366FC26F0D2980076364C /* UIButton+EnlargeTouchArea.m in Sources */ = {isa = PBXBuildFile; fileRef = E81366FA26F0D2980076364C /* UIButton+EnlargeTouchArea.m */; }; E816C11527608A7500C84014 /* XPRoomMiniManager.m in Sources */ = {isa = PBXBuildFile; fileRef = E816C11427608A7500C84014 /* XPRoomMiniManager.m */; }; + E81AF31A27F19265003B9E43 /* XPHomeGradientLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = E81AF31927F19265003B9E43 /* XPHomeGradientLabel.m */; }; E81C1B1C27705F6B0020D1E4 /* XPArrangeMicPresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = E81C1B1B27705F6B0020D1E4 /* XPArrangeMicPresenter.m */; }; E81C1B1F27705F7A0020D1E4 /* XPArrangeMicViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E81C1B1E27705F7A0020D1E4 /* XPArrangeMicViewController.m */; }; E81C1B2227705F950020D1E4 /* Api+ArrangeMic.m in Sources */ = {isa = PBXBuildFile; fileRef = E81C1B2127705F950020D1E4 /* Api+ArrangeMic.m */; }; @@ -1054,6 +1055,8 @@ E81366FB26F0D2980076364C /* UIButton+EnlargeTouchArea.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIButton+EnlargeTouchArea.h"; sourceTree = ""; }; E816C11327608A7500C84014 /* XPRoomMiniManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPRoomMiniManager.h; sourceTree = ""; }; E816C11427608A7500C84014 /* XPRoomMiniManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPRoomMiniManager.m; sourceTree = ""; }; + E81AF31827F19265003B9E43 /* XPHomeGradientLabel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPHomeGradientLabel.h; sourceTree = ""; }; + E81AF31927F19265003B9E43 /* XPHomeGradientLabel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPHomeGradientLabel.m; sourceTree = ""; }; E81C1B1927705F4B0020D1E4 /* XPArrangeMicProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPArrangeMicProtocol.h; sourceTree = ""; }; E81C1B1A27705F6B0020D1E4 /* XPArrangeMicPresenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPArrangeMicPresenter.h; sourceTree = ""; }; E81C1B1B27705F6B0020D1E4 /* XPArrangeMicPresenter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPArrangeMicPresenter.m; sourceTree = ""; }; @@ -4638,6 +4641,8 @@ E8E5E1A227C3730B00F457D8 /* XPHomeSectionView.m */, E80CBDEE27D0E2C8001E1EC2 /* XPHomeRecommendOtherRoomView.h */, E80CBDEF27D0E2C8001E1EC2 /* XPHomeRecommendOtherRoomView.m */, + E81AF31827F19265003B9E43 /* XPHomeGradientLabel.h */, + E81AF31927F19265003B9E43 /* XPHomeGradientLabel.m */, ); path = SubViews; sourceTree = ""; @@ -5258,6 +5263,7 @@ 9B060B5827BCAEE20001B767 /* AnchorGiftValueView.m in Sources */, E880B3B2278C1D1800A83B0D /* XPAcrossRoomPKRuleView.m in Sources */, E81C1B262770663B0020D1E4 /* XPArrangeMicTableViewCell.m in Sources */, + E81AF31A27F19265003B9E43 /* XPHomeGradientLabel.m in Sources */, E8AC722F26F49610007D6E91 /* XPMineNotificationItemModel.m in Sources */, E8E70D7A26F2F16600F03460 /* XPMinePresent.m in Sources */, E8A1E45B27620F4900B294CA /* XPRoomHalfWebView.m in Sources */, diff --git a/xplan-ios/Main/Home/View/Cell/XPHomeLittleGameTableViewCell.m b/xplan-ios/Main/Home/View/Cell/XPHomeLittleGameTableViewCell.m index 33161a43..0394c9f8 100644 --- a/xplan-ios/Main/Home/View/Cell/XPHomeLittleGameTableViewCell.m +++ b/xplan-ios/Main/Home/View/Cell/XPHomeLittleGameTableViewCell.m @@ -13,6 +13,7 @@ #import "NetImageView.h" #import "XPMacro.h" #import "UIImage+Utils.h" +#import "XPHomeGradientLabel.h" ///Model #import "HomeLittleGameRoomModel.h" @@ -26,7 +27,7 @@ ///房间标题 @property (nonatomic,strong) UILabel *roomTitleLabel; ///游戏名字 -@property (nonatomic,strong) UILabel *gamenameLabel; +@property (nonatomic,strong) XPHomeGradientLabel *gamenameLabel; ///分割线 @property (nonatomic,strong) UIView * gameLineView; ///游戏状态 @@ -74,11 +75,11 @@ [self.backImageView addSubview:self.micContainerView]; [self.backImageView addSubview:self.enterButton]; - [self.micContainerView addSubview:self.fifImageView]; - [self.micContainerView addSubview:self.fourImageView]; - [self.micContainerView addSubview:self.thirdImageView]; - [self.micContainerView addSubview:self.secondImageView]; [self.micContainerView addSubview:self.firstImageView]; + [self.micContainerView addSubview:self.secondImageView]; + [self.micContainerView addSubview:self.thirdImageView]; + [self.micContainerView addSubview:self.fourImageView]; + [self.micContainerView addSubview:self.fifImageView]; self.micUserArray = @[self.firstImageView, self.secondImageView, self.thirdImageView, self.fourImageView, self.fifImageView]; } @@ -127,36 +128,36 @@ }]; [self.micContainerView mas_makeConstraints:^(MASConstraintMaker *make) { - make.right.mas_equalTo(self.backImageView).offset(-13); - make.height.mas_equalTo(16); + make.right.mas_equalTo(self.fifImageView.mas_right).offset(3); + make.height.mas_equalTo(32); make.top.mas_equalTo(self.gamenameLabel.mas_bottom).offset(10); - make.left.mas_equalTo(self.fifImageView.mas_left).offset(-5); + make.left.mas_equalTo(self.roomTitleLabel); }]; [self.firstImageView mas_makeConstraints:^(MASConstraintMaker *make) { - make.size.mas_equalTo(CGSizeMake(16, 16)); - make.right.mas_equalTo(self.micContainerView); + make.size.mas_equalTo(CGSizeMake(32, 32)); + make.left.mas_equalTo(self.micContainerView); make.centerY.mas_equalTo(self.micContainerView); }]; [self.secondImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.centerY.mas_equalTo(self.firstImageView); - make.right.mas_equalTo(self.firstImageView.mas_left).offset(2); + make.left.mas_equalTo(self.firstImageView.mas_right).offset(-4); }]; [self.thirdImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.centerY.mas_equalTo(self.firstImageView); - make.right.mas_equalTo(self.secondImageView.mas_left).offset(2); + make.left.mas_equalTo(self.secondImageView.mas_right).offset(-4); }]; [self.fourImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.centerY.mas_equalTo(self.firstImageView); - make.right.mas_equalTo(self.thirdImageView.mas_left).offset(2); + make.left.mas_equalTo(self.thirdImageView.mas_right).offset(-4); }]; [self.fifImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.centerY.mas_equalTo(self.firstImageView); - make.right.mas_equalTo(self.fourImageView.mas_left).offset(2); + make.left.mas_equalTo(self.fourImageView.mas_right).offset(-4); }]; } #pragma mark - Getters And Setters @@ -166,6 +167,7 @@ self.roomTitleLabel.text = _gameInfo.title; self.avatarImageView.imageUrl = _gameInfo.avatar; self.gamenameLabel.text = _gameInfo.mgName; + [self.roomTitleLabel setNeedsDisplay]; self.stateLabel.text = _gameInfo.state == 1 ? @"游戏中" : @"等待中"; if (_gameInfo.micUsers.count > 0) { self.micContainerView.hidden = NO; @@ -227,10 +229,11 @@ return _roomTitleLabel; } -- (UILabel *)gamenameLabel { +- (XPHomeGradientLabel *)gamenameLabel { if (!_gamenameLabel) { - _gamenameLabel = [[UILabel alloc] init]; + _gamenameLabel = [[XPHomeGradientLabel alloc] init]; _gamenameLabel.font = [UIFont systemFontOfSize:10]; + _gamenameLabel.gradientColor = @[(id)UIColorFromRGB(0x61C4FE).CGColor, (id)UIColorFromRGB(0xA979FF).CGColor]; } return _gamenameLabel; } @@ -283,10 +286,9 @@ config.placeHolder = [UIImageConstant defaultAvatarPlaceholder]; _firstImageView = [[NetImageView alloc] initWithConfig:config]; _firstImageView.layer.masksToBounds = YES; - _firstImageView.layer.cornerRadius = 8; + _firstImageView.layer.cornerRadius = 16; _firstImageView.layer.borderColor = [UIColor whiteColor].CGColor; - _firstImageView.layer.borderWidth = 1; - _firstImageView.backgroundColor= [UIColor redColor]; + _firstImageView.layer.borderWidth = 2; } return _firstImageView; } @@ -298,10 +300,9 @@ config.placeHolder = [UIImageConstant defaultAvatarPlaceholder]; _secondImageView = [[NetImageView alloc] initWithConfig:config]; _secondImageView.layer.masksToBounds = YES; - _secondImageView.layer.cornerRadius = 8; + _secondImageView.layer.cornerRadius = 16; _secondImageView.layer.borderColor = [UIColor whiteColor].CGColor; - _secondImageView.layer.borderWidth = 1; - _secondImageView.backgroundColor= [UIColor yellowColor]; + _secondImageView.layer.borderWidth = 2; } return _secondImageView; } @@ -313,10 +314,9 @@ config.placeHolder = [UIImageConstant defaultAvatarPlaceholder]; _thirdImageView = [[NetImageView alloc] initWithConfig:config]; _thirdImageView.layer.masksToBounds = YES; - _thirdImageView.layer.cornerRadius = 8; + _thirdImageView.layer.cornerRadius = 16; _thirdImageView.layer.borderColor = [UIColor whiteColor].CGColor; - _thirdImageView.layer.borderWidth = 1; - _thirdImageView.backgroundColor= [UIColor blueColor]; + _thirdImageView.layer.borderWidth = 2; } return _thirdImageView; } @@ -328,9 +328,9 @@ config.placeHolder = [UIImageConstant defaultAvatarPlaceholder]; _fourImageView = [[NetImageView alloc] initWithConfig:config]; _fourImageView.layer.masksToBounds = YES; - _fourImageView.layer.cornerRadius = 8; + _fourImageView.layer.cornerRadius = 16; _fourImageView.layer.borderColor = [UIColor whiteColor].CGColor; - _fourImageView.layer.borderWidth = 1; + _fourImageView.layer.borderWidth = 2; } return _fourImageView; } @@ -343,9 +343,9 @@ config.placeHolder = [UIImageConstant defaultAvatarPlaceholder]; _fifImageView = [[NetImageView alloc] initWithConfig:config]; _fifImageView.layer.masksToBounds = YES; - _fifImageView.layer.cornerRadius = 8; + _fifImageView.layer.cornerRadius = 16; _fifImageView.layer.borderColor = [UIColor whiteColor].CGColor; - _fifImageView.layer.borderWidth = 1; + _fifImageView.layer.borderWidth = 2; } return _fifImageView; } diff --git a/xplan-ios/Main/Home/View/SubViews/XPHomeGradientLabel.h b/xplan-ios/Main/Home/View/SubViews/XPHomeGradientLabel.h new file mode 100644 index 00000000..12b40a9b --- /dev/null +++ b/xplan-ios/Main/Home/View/SubViews/XPHomeGradientLabel.h @@ -0,0 +1,17 @@ +// +// XPHomeGradientLabel.h +// xplan-ios +// +// Created by 冯硕 on 2022/3/28. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface XPHomeGradientLabel : UILabel +///渐变色 +@property (nonatomic,strong) NSArray *gradientColor; +@end + +NS_ASSUME_NONNULL_END diff --git a/xplan-ios/Main/Home/View/SubViews/XPHomeGradientLabel.m b/xplan-ios/Main/Home/View/SubViews/XPHomeGradientLabel.m new file mode 100644 index 00000000..80fef9ff --- /dev/null +++ b/xplan-ios/Main/Home/View/SubViews/XPHomeGradientLabel.m @@ -0,0 +1,43 @@ +// +// XPHomeGradientLabel.m +// xplan-ios +// +// Created by 冯硕 on 2022/3/28. +// + +#import "XPHomeGradientLabel.h" + +@implementation XPHomeGradientLabel + +- (void)drawRect:(CGRect)rect{ + CGSize textSize = [self.text sizeWithAttributes:@{NSFontAttributeName : self.font}]; + CGRect textRect = (CGRect){0, 0, textSize}; + // 画文字(不做显示用 主要作用是设置layer的mask) + CGContextRef context = UIGraphicsGetCurrentContext(); + [self.textColor set]; + [self.text drawWithRect:rect options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : self.font} context:NULL]; + // 坐标 (只对设置后的画到context起作用 之前画的文字不起作用) + CGContextTranslateCTM(context, 0.0f, rect.size.height- (rect.size.height - textSize.height)*0.5); + CGContextScaleCTM(context, 1.0f, -1.0f); + CGImageRef alphaMask = NULL; + alphaMask = CGBitmapContextCreateImage(context); + CGContextClearRect(context, rect);// 清除之前画的文字 + // 设置mask + CGContextClipToMask(context, rect, alphaMask); + // 画渐变色 + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)self.gradientColor, NULL); + CGPoint startPoint = CGPointMake(textRect.origin.x, + textRect.origin.y); + CGPoint endPoint = CGPointMake(textRect.origin.x + textRect.size.width, + textRect.origin.y + textRect.size.height); + CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation); + // 释放内存 + CGColorSpaceRelease(colorSpace); + CGGradientRelease(gradient); + CFRelease(alphaMask); + +} + + +@end