1
This commit is contained in:
@@ -144,6 +144,7 @@
|
||||
048FFD1D2F277486005D62AE /* KBChatHistoryPageModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 048FFD1C2F277486005D62AE /* KBChatHistoryPageModel.m */; };
|
||||
048FFD1E2F277486005D62AE /* KBChatHistoryModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 048FFD1A2F277486005D62AE /* KBChatHistoryModel.m */; };
|
||||
048FFD242F28A836005D62AE /* KBChatLimitPopView.m in Sources */ = {isa = PBXBuildFile; fileRef = 048FFD232F28A836005D62AE /* KBChatLimitPopView.m */; };
|
||||
048FFD272F28C6CF005D62AE /* KBImagePositionButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 048FFD262F28C6CF005D62AE /* KBImagePositionButton.m */; };
|
||||
0498BD622EDFFC12006CC1D5 /* KBMyVM.m in Sources */ = {isa = PBXBuildFile; fileRef = 0498BD612EDFFC12006CC1D5 /* KBMyVM.m */; };
|
||||
0498BD652EE0116D006CC1D5 /* KBEmailLoginVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 0498BD642EE0116D006CC1D5 /* KBEmailLoginVC.m */; };
|
||||
0498BD682EE01180006CC1D5 /* KBEmailRegistVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 0498BD672EE01180006CC1D5 /* KBEmailRegistVC.m */; };
|
||||
@@ -544,6 +545,8 @@
|
||||
048FFD1C2F277486005D62AE /* KBChatHistoryPageModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBChatHistoryPageModel.m; sourceTree = "<group>"; };
|
||||
048FFD222F28A836005D62AE /* KBChatLimitPopView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBChatLimitPopView.h; sourceTree = "<group>"; };
|
||||
048FFD232F28A836005D62AE /* KBChatLimitPopView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBChatLimitPopView.m; sourceTree = "<group>"; };
|
||||
048FFD252F28C6CF005D62AE /* KBImagePositionButton.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBImagePositionButton.h; sourceTree = "<group>"; };
|
||||
048FFD262F28C6CF005D62AE /* KBImagePositionButton.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBImagePositionButton.m; sourceTree = "<group>"; };
|
||||
0498BD5E2EDF2157006CC1D5 /* KBBizCode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBBizCode.h; sourceTree = "<group>"; };
|
||||
0498BD602EDFFC12006CC1D5 /* KBMyVM.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBMyVM.h; sourceTree = "<group>"; };
|
||||
0498BD612EDFFC12006CC1D5 /* KBMyVM.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBMyVM.m; sourceTree = "<group>"; };
|
||||
@@ -1234,6 +1237,8 @@
|
||||
049FB20D2EC1CD2800FAB05D /* KBAlert.m */,
|
||||
042869FD2ECAEF2B00CE730C /* KBMoneyBtn.h */,
|
||||
042869FE2ECAEF2B00CE730C /* KBMoneyBtn.m */,
|
||||
048FFD252F28C6CF005D62AE /* KBImagePositionButton.h */,
|
||||
048FFD262F28C6CF005D62AE /* KBImagePositionButton.m */,
|
||||
);
|
||||
path = V;
|
||||
sourceTree = "<group>";
|
||||
@@ -2444,6 +2449,7 @@
|
||||
0477BEA22EBCF0000055D639 /* KBTopImageButton.m in Sources */,
|
||||
A1B2E1012EBC7AAA00000001 /* KBTopThreeView.m in Sources */,
|
||||
A1B2E1022EBC7AAA00000001 /* HomeHotCell.m in Sources */,
|
||||
048FFD272F28C6CF005D62AE /* KBImagePositionButton.m in Sources */,
|
||||
0459D1B72EBA287900F2D189 /* KBSkinManager.m in Sources */,
|
||||
04286A002ECAEF2B00CE730C /* KBMoneyBtn.m in Sources */,
|
||||
048908F52EC0496400FABA60 /* KBShopItemVC.m in Sources */,
|
||||
|
||||
22
keyBoard/Assets.xcassets/AI/ai_comment_icon.imageset/Contents.json
vendored
Normal file
22
keyBoard/Assets.xcassets/AI/ai_comment_icon.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"filename" : "ai_comment_icon@2x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"filename" : "ai_comment_icon@3x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
BIN
keyBoard/Assets.xcassets/AI/ai_comment_icon.imageset/ai_comment_icon@2x.png
vendored
Normal file
BIN
keyBoard/Assets.xcassets/AI/ai_comment_icon.imageset/ai_comment_icon@2x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 847 B |
BIN
keyBoard/Assets.xcassets/AI/ai_comment_icon.imageset/ai_comment_icon@3x.png
vendored
Normal file
BIN
keyBoard/Assets.xcassets/AI/ai_comment_icon.imageset/ai_comment_icon@3x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
22
keyBoard/Assets.xcassets/AI/ai_live_icon.imageset/Contents.json
vendored
Normal file
22
keyBoard/Assets.xcassets/AI/ai_live_icon.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"filename" : "ai_live_icon@2x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"filename" : "ai_live_icon@3x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
BIN
keyBoard/Assets.xcassets/AI/ai_live_icon.imageset/ai_live_icon@2x.png
vendored
Normal file
BIN
keyBoard/Assets.xcassets/AI/ai_live_icon.imageset/ai_live_icon@2x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
BIN
keyBoard/Assets.xcassets/AI/ai_live_icon.imageset/ai_live_icon@3x.png
vendored
Normal file
BIN
keyBoard/Assets.xcassets/AI/ai_live_icon.imageset/ai_live_icon@3x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
22
keyBoard/Assets.xcassets/AI/ai_livesel_icon.imageset/Contents.json
vendored
Normal file
22
keyBoard/Assets.xcassets/AI/ai_livesel_icon.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"filename" : "ai_livesel_icon@2x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"filename" : "ai_livesel_icon@3x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
BIN
keyBoard/Assets.xcassets/AI/ai_livesel_icon.imageset/ai_livesel_icon@2x.png
vendored
Normal file
BIN
keyBoard/Assets.xcassets/AI/ai_livesel_icon.imageset/ai_livesel_icon@2x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
keyBoard/Assets.xcassets/AI/ai_livesel_icon.imageset/ai_livesel_icon@3x.png
vendored
Normal file
BIN
keyBoard/Assets.xcassets/AI/ai_livesel_icon.imageset/ai_livesel_icon@3x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
@@ -74,6 +74,13 @@ typedef NS_ENUM(NSInteger, KBPersonaVisibility) {
|
||||
|
||||
/// 更新时间
|
||||
@property (nonatomic, copy) NSString *updatedAt;
|
||||
/// 评论数
|
||||
@property (nonatomic, copy) NSString *commentCount;
|
||||
/// 喜欢数
|
||||
@property (nonatomic, copy) NSString *likeCount;
|
||||
/// 是否喜欢
|
||||
@property (nonatomic, assign) BOOL liked;
|
||||
|
||||
|
||||
#pragma mark - 扩展属性
|
||||
|
||||
|
||||
@@ -89,7 +89,8 @@ static const NSTimeInterval kTimestampInterval = 5 * 60; // 5 分钟
|
||||
make.edges.equalTo(self);
|
||||
}];
|
||||
|
||||
self.contentBottomInset = KB_TABBAR_HEIGHT + 40 + 10;
|
||||
// 关键修复:减少初始 contentBottomInset,因为 chatView 已经通过约束避开了底部
|
||||
self.contentBottomInset = 20; // 简单的缓冲空间
|
||||
[self updateContentBottomInset:self.contentBottomInset];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#import "KBAiChatMessage.h"
|
||||
#import "KBChatHistoryPageModel.h"
|
||||
#import "AiVM.h"
|
||||
#import "KBImagePositionButton.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
#import <SDWebImage/SDWebImage.h>
|
||||
|
||||
@@ -48,6 +49,12 @@
|
||||
/// AiVM 实例
|
||||
@property (nonatomic, strong) AiVM *aiVM;
|
||||
|
||||
/// 评论按钮
|
||||
@property (nonatomic, strong) KBImagePositionButton *commentButton;
|
||||
|
||||
/// 喜欢按钮
|
||||
@property (nonatomic, strong) KBImagePositionButton *likeButton;
|
||||
|
||||
@end
|
||||
|
||||
@implementation KBPersonaChatCell
|
||||
@@ -113,6 +120,24 @@
|
||||
make.centerY.equalTo(self.avatarImageView);
|
||||
}];
|
||||
|
||||
// 评论按钮(最右侧)
|
||||
[self.contentView addSubview:self.commentButton];
|
||||
[self.commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.equalTo(self.contentView).offset(-20);
|
||||
make.centerY.equalTo(self.avatarImageView);
|
||||
make.width.mas_equalTo(40);
|
||||
make.height.mas_equalTo(50);
|
||||
}];
|
||||
|
||||
// 喜欢按钮(评论按钮左侧,间距20px)
|
||||
[self.contentView addSubview:self.likeButton];
|
||||
[self.likeButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.equalTo(self.commentButton.mas_left).offset(-20);
|
||||
make.centerY.equalTo(self.avatarImageView);
|
||||
make.width.mas_equalTo(40);
|
||||
make.height.mas_equalTo(50);
|
||||
}];
|
||||
|
||||
// 聊天列表
|
||||
[self.contentView addSubview:self.chatView];
|
||||
[self.chatView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
@@ -147,6 +172,10 @@
|
||||
// 关键修复:清空消息时停止音频播放,避免状态混乱
|
||||
[self.chatView stopPlayingAudio];
|
||||
[self.chatView clearMessages];
|
||||
[self.commentButton setTitle:persona.commentCount forState:UIControlStateNormal];
|
||||
[self.likeButton setTitle:persona.likeCount forState:UIControlStateNormal];
|
||||
self.likeButton.selected = persona.liked;
|
||||
|
||||
}
|
||||
|
||||
#pragma mark - 2:数据加载
|
||||
@@ -350,7 +379,7 @@
|
||||
- (UILabel *)nameLabel {
|
||||
if (!_nameLabel) {
|
||||
_nameLabel = [[UILabel alloc] init];
|
||||
_nameLabel.font = [UIFont boldSystemFontOfSize:20];
|
||||
_nameLabel.font = [UIFont boldSystemFontOfSize:12];
|
||||
_nameLabel.textColor = [UIColor whiteColor];
|
||||
_nameLabel.textAlignment = NSTextAlignmentCenter;
|
||||
}
|
||||
@@ -377,4 +406,63 @@
|
||||
return _chatView;
|
||||
}
|
||||
|
||||
- (KBImagePositionButton *)commentButton {
|
||||
if (!_commentButton) {
|
||||
// 创建上图下文的按钮
|
||||
_commentButton = [[KBImagePositionButton alloc] initWithImagePosition:KBImagePositionTop spacing:4];
|
||||
|
||||
// 关键修复:先设置字体,再设置文字,避免循环调用
|
||||
_commentButton.titleLabel.font = [UIFont systemFontOfSize:10];
|
||||
|
||||
// 设置图片
|
||||
[_commentButton setImage:[UIImage imageNamed:@"ai_comment_icon"] forState:UIControlStateNormal];
|
||||
|
||||
// 设置文字
|
||||
[_commentButton setTitle:@"0" forState:UIControlStateNormal];
|
||||
[_commentButton setTitleColor:[[UIColor whiteColor] colorWithAlphaComponent:0.8] forState:UIControlStateNormal];
|
||||
|
||||
// 添加点击事件
|
||||
[_commentButton addTarget:self action:@selector(commentButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _commentButton;
|
||||
}
|
||||
|
||||
- (KBImagePositionButton *)likeButton {
|
||||
if (!_likeButton) {
|
||||
// 创建上图下文的按钮
|
||||
_likeButton = [[KBImagePositionButton alloc] initWithImagePosition:KBImagePositionTop spacing:4];
|
||||
|
||||
// 关键修复:先设置字体,再设置文字,避免循环调用
|
||||
_likeButton.titleLabel.font = [UIFont systemFontOfSize:10];
|
||||
|
||||
// 设置图片
|
||||
[_likeButton setImage:[UIImage imageNamed:@"ai_live_icon"] forState:UIControlStateNormal];
|
||||
[_likeButton setImage:[UIImage imageNamed:@"ai_livesel_icon"] forState:UIControlStateSelected];
|
||||
|
||||
// 设置文字
|
||||
[_likeButton setTitle:@"0" forState:UIControlStateNormal];
|
||||
[_likeButton setTitleColor:[[UIColor whiteColor] colorWithAlphaComponent:0.8] forState:UIControlStateNormal];
|
||||
|
||||
// 添加点击事件
|
||||
[_likeButton addTarget:self action:@selector(likeButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _likeButton;
|
||||
}
|
||||
|
||||
#pragma mark - Button Actions
|
||||
|
||||
- (void)commentButtonTapped:(KBImagePositionButton *)sender {
|
||||
sender.selected = !sender.selected;
|
||||
NSLog(@"[KBPersonaChatCell] 评论按钮点击,选中状态:%d", sender.selected);
|
||||
|
||||
// TODO: 在这里添加评论逻辑
|
||||
}
|
||||
|
||||
- (void)likeButtonTapped:(KBImagePositionButton *)sender {
|
||||
sender.selected = !sender.selected;
|
||||
NSLog(@"[KBPersonaChatCell] 喜欢按钮点击,选中状态:%d", sender.selected);
|
||||
|
||||
// TODO: 在这里添加喜欢逻辑
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -422,7 +422,12 @@
|
||||
|
||||
- (void)updateChatViewBottomInset {
|
||||
CGFloat bottomSpacing = (self.currentKeyboardHeight > 0.0) ? (self.currentKeyboardHeight + 8.0) : self.baseInputBarBottomSpacing;
|
||||
CGFloat bottomInset = self.voiceInputBarHeight + bottomSpacing;
|
||||
|
||||
// 关键修复:减少 bottomInset,因为 chatView 已经通过约束避开了底部的 avatar 区域
|
||||
// 只需要留出一点空间(比如20)让最后一条消息不紧贴 chatView 底部即可
|
||||
CGFloat bottomInset = 20; // 简单的缓冲空间
|
||||
|
||||
NSLog(@"[KBAIHomeVC] 更新 ChatView bottomInset: %.2f", bottomInset);
|
||||
|
||||
for (NSIndexPath *indexPath in self.collectionView.indexPathsForVisibleItems) {
|
||||
KBPersonaChatCell *cell = (KBPersonaChatCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
|
||||
|
||||
39
keyBoard/Class/Common/V/KBImagePositionButton.h
Normal file
39
keyBoard/Class/Common/V/KBImagePositionButton.h
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// KBImagePositionButton.h
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Kiro on 2026/1/27.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/// 图片位置枚举
|
||||
typedef NS_ENUM(NSInteger, KBImagePosition) {
|
||||
KBImagePositionTop, // 图片在上,文字在下
|
||||
KBImagePositionBottom, // 图片在下,文字在上
|
||||
KBImagePositionLeft, // 图片在左,文字在右(默认)
|
||||
KBImagePositionRight // 图片在右,文字在左
|
||||
};
|
||||
|
||||
/// 可以指定图片位置的按钮
|
||||
@interface KBImagePositionButton : UIButton
|
||||
|
||||
/// 图片位置(默认 KBImagePositionLeft)
|
||||
@property (nonatomic, assign) KBImagePosition imagePosition;
|
||||
|
||||
/// 图片和文字之间的间距(默认 8)
|
||||
@property (nonatomic, assign) CGFloat spacing;
|
||||
|
||||
/**
|
||||
便捷初始化方法
|
||||
|
||||
@param imagePosition 图片位置
|
||||
@param spacing 图片和文字之间的间距
|
||||
*/
|
||||
- (instancetype)initWithImagePosition:(KBImagePosition)imagePosition spacing:(CGFloat)spacing;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
187
keyBoard/Class/Common/V/KBImagePositionButton.m
Normal file
187
keyBoard/Class/Common/V/KBImagePositionButton.m
Normal file
@@ -0,0 +1,187 @@
|
||||
//
|
||||
// KBImagePositionButton.m
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Kiro on 2026/1/27.
|
||||
//
|
||||
|
||||
#import "KBImagePositionButton.h"
|
||||
|
||||
@implementation KBImagePositionButton
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
[self setupDefault];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
||||
if (self = [super initWithCoder:coder]) {
|
||||
[self setupDefault];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithImagePosition:(KBImagePosition)imagePosition spacing:(CGFloat)spacing {
|
||||
if (self = [super initWithFrame:CGRectZero]) {
|
||||
_imagePosition = imagePosition;
|
||||
_spacing = spacing;
|
||||
[self setupDefault];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setupDefault {
|
||||
// 关键修复:不要判断 _imagePosition == 0,因为 KBImagePositionTop 的值就是 0
|
||||
// 如果是通过 initWithFrame 或 initWithCoder 初始化,_imagePosition 默认就是 0 (KBImagePositionTop)
|
||||
// 只有通过 initWithImagePosition 初始化时,才会明确设置 _imagePosition
|
||||
|
||||
// 为非自定义初始化设置默认值
|
||||
if (self.spacing == 0) {
|
||||
_spacing = 8;
|
||||
}
|
||||
|
||||
[self updateEdgeInsets];
|
||||
}
|
||||
|
||||
#pragma mark - Setter
|
||||
|
||||
- (void)setImagePosition:(KBImagePosition)imagePosition {
|
||||
_imagePosition = imagePosition;
|
||||
[self updateEdgeInsets];
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
- (void)setSpacing:(CGFloat)spacing {
|
||||
_spacing = spacing;
|
||||
[self updateEdgeInsets];
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
- (void)setImage:(UIImage *)image forState:(UIControlState)state {
|
||||
[super setImage:image forState:state];
|
||||
// 延迟更新,确保 image 已经设置好
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self updateEdgeInsets];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)setTitle:(NSString *)title forState:(UIControlState)state {
|
||||
[super setTitle:title forState:state];
|
||||
// 延迟更新,确保 title 已经设置好
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self updateEdgeInsets];
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark - EdgeInsets
|
||||
|
||||
- (void)updateEdgeInsets {
|
||||
CGSize imageSize = self.currentImage.size;
|
||||
CGSize titleSize = CGSizeZero;
|
||||
|
||||
if (self.currentTitle.length > 0 && self.titleLabel.font) {
|
||||
NSDictionary *attributes = @{NSFontAttributeName: self.titleLabel.font};
|
||||
titleSize = [self.currentTitle sizeWithAttributes:attributes];
|
||||
}
|
||||
|
||||
switch (self.imagePosition) {
|
||||
case KBImagePositionTop: {
|
||||
// 图片在上,文字在下
|
||||
self.imageEdgeInsets = UIEdgeInsetsMake(
|
||||
-(titleSize.height + self.spacing), // top: 向上移动
|
||||
0, // left
|
||||
0, // bottom
|
||||
-titleSize.width // right: 向左移动文字的宽度
|
||||
);
|
||||
|
||||
self.titleEdgeInsets = UIEdgeInsetsMake(
|
||||
imageSize.height + self.spacing, // top: 向下移动
|
||||
-imageSize.width, // left: 向左移动图片的宽度
|
||||
0, // bottom
|
||||
0 // right
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case KBImagePositionBottom: {
|
||||
// 图片在下,文字在上
|
||||
self.imageEdgeInsets = UIEdgeInsetsMake(
|
||||
titleSize.height + self.spacing, // top: 向下移动
|
||||
0, // left
|
||||
0, // bottom
|
||||
-titleSize.width // right
|
||||
);
|
||||
|
||||
self.titleEdgeInsets = UIEdgeInsetsMake(
|
||||
-(imageSize.height + self.spacing), // top: 向上移动
|
||||
-imageSize.width, // left
|
||||
0, // bottom
|
||||
0 // right
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case KBImagePositionLeft: {
|
||||
// 图片在左,文字在右(默认)
|
||||
self.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, self.spacing);
|
||||
self.titleEdgeInsets = UIEdgeInsetsMake(0, self.spacing, 0, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
case KBImagePositionRight: {
|
||||
// 图片在右,文字在左
|
||||
self.imageEdgeInsets = UIEdgeInsetsMake(
|
||||
0,
|
||||
titleSize.width + self.spacing,
|
||||
0,
|
||||
-(titleSize.width + self.spacing)
|
||||
);
|
||||
|
||||
self.titleEdgeInsets = UIEdgeInsetsMake(
|
||||
0,
|
||||
-(imageSize.width + self.spacing),
|
||||
0,
|
||||
imageSize.width + self.spacing
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
NSLog(@"imageEdgeInsets: %@", NSStringFromUIEdgeInsets(self.imageEdgeInsets));
|
||||
NSLog(@"titleEdgeInsets: %@", NSStringFromUIEdgeInsets(self.titleEdgeInsets));
|
||||
}
|
||||
|
||||
- (CGSize)intrinsicContentSize {
|
||||
CGSize imageSize = self.currentImage ? self.currentImage.size : CGSizeZero;
|
||||
CGSize titleSize = CGSizeZero;
|
||||
|
||||
if (self.currentTitle.length > 0 && self.titleLabel.font) {
|
||||
NSDictionary *attributes = @{NSFontAttributeName: self.titleLabel.font};
|
||||
titleSize = [self.currentTitle sizeWithAttributes:attributes];
|
||||
}
|
||||
|
||||
CGSize size = CGSizeZero;
|
||||
|
||||
switch (self.imagePosition) {
|
||||
case KBImagePositionTop:
|
||||
case KBImagePositionBottom: {
|
||||
// 垂直排列
|
||||
size.width = MAX(imageSize.width, titleSize.width);
|
||||
size.height = imageSize.height + self.spacing + titleSize.height;
|
||||
break;
|
||||
}
|
||||
|
||||
case KBImagePositionLeft:
|
||||
case KBImagePositionRight: {
|
||||
// 水平排列
|
||||
size.width = imageSize.width + self.spacing + titleSize.width;
|
||||
size.height = MAX(imageSize.height, titleSize.height);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user