首页小游戏列表名字渐变色

This commit is contained in:
fengshuo
2022-03-28 15:00:50 +08:00
committed by chenguilong
parent b0b0c0765d
commit e2b4617048
4 changed files with 95 additions and 29 deletions

View File

@@ -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 = "<group>"; };
E816C11327608A7500C84014 /* XPRoomMiniManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPRoomMiniManager.h; sourceTree = "<group>"; };
E816C11427608A7500C84014 /* XPRoomMiniManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPRoomMiniManager.m; sourceTree = "<group>"; };
E81AF31827F19265003B9E43 /* XPHomeGradientLabel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPHomeGradientLabel.h; sourceTree = "<group>"; };
E81AF31927F19265003B9E43 /* XPHomeGradientLabel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPHomeGradientLabel.m; sourceTree = "<group>"; };
E81C1B1927705F4B0020D1E4 /* XPArrangeMicProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPArrangeMicProtocol.h; sourceTree = "<group>"; };
E81C1B1A27705F6B0020D1E4 /* XPArrangeMicPresenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPArrangeMicPresenter.h; sourceTree = "<group>"; };
E81C1B1B27705F6B0020D1E4 /* XPArrangeMicPresenter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPArrangeMicPresenter.m; sourceTree = "<group>"; };
@@ -4638,6 +4641,8 @@
E8E5E1A227C3730B00F457D8 /* XPHomeSectionView.m */,
E80CBDEE27D0E2C8001E1EC2 /* XPHomeRecommendOtherRoomView.h */,
E80CBDEF27D0E2C8001E1EC2 /* XPHomeRecommendOtherRoomView.m */,
E81AF31827F19265003B9E43 /* XPHomeGradientLabel.h */,
E81AF31927F19265003B9E43 /* XPHomeGradientLabel.m */,
);
path = SubViews;
sourceTree = "<group>";
@@ -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 */,

View File

@@ -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;
}

View File

@@ -0,0 +1,17 @@
//
// XPHomeGradientLabel.h
// xplan-ios
//
// Created by 冯硕 on 2022/3/28.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface XPHomeGradientLabel : UILabel
///渐变色
@property (nonatomic,strong) NSArray *gradientColor;
@end
NS_ASSUME_NONNULL_END

View File

@@ -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};
// ( layermask)
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