修改
This commit is contained in:
@@ -81,25 +81,26 @@ static NSString *identifier = @"AvatarCollectionViewCell";
|
||||
if (ISNULLSTR(link.icon)) {
|
||||
cell.avatarImageView.image = [self circularImageWithText:link.name];
|
||||
}else{
|
||||
NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:link.icon] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
|
||||
if (error) {
|
||||
NSLog(@"Error downloading image: %@", error);
|
||||
} else {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIImage *image = [UIImage imageWithData:data];
|
||||
cell.avatarImageView.image = image;
|
||||
});
|
||||
}
|
||||
}];
|
||||
[dataTask resume];
|
||||
cell.avatarImageView.image = [UIImage imageNamed:link.icon];
|
||||
// NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:link.icon] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
|
||||
// if (error) {
|
||||
// NSLog(@"Error downloading image: %@", error);
|
||||
// } else {
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// UIImage *image = [UIImage imageWithData:data];
|
||||
// cell.avatarImageView.image = image;
|
||||
// });
|
||||
// }
|
||||
// }];
|
||||
// [dataTask resume];
|
||||
}
|
||||
}else if ([value isKindOfClass:[NSNumber class]]) {
|
||||
NSNumber *number = value;
|
||||
DSWebMenuType type = number.integerValue;
|
||||
if (type == DSWebMenuHomeType) {
|
||||
cell.avatarImageView.image = [UIImage imageNamed:@"menu"];
|
||||
cell.avatarImageView.image = [UIImage imageNamed:@"menu2"];
|
||||
}else if (type == DSWebMenuRefreshType) {
|
||||
cell.avatarImageView.image = [UIImage imageNamed:@"refresh"];
|
||||
cell.avatarImageView.image = [UIImage imageNamed:@"refresh2"];
|
||||
}else if (type == DSWebMenuTelegramType) {
|
||||
cell.avatarImageView.image = [UIImage imageNamed:@"telegram"];
|
||||
}else if (type == DSWebMenuWhatsAppType) {
|
||||
@@ -107,10 +108,10 @@ static NSString *identifier = @"AvatarCollectionViewCell";
|
||||
}else if (type == DSWebMenuFacebookType) {
|
||||
cell.avatarImageView.image = [UIImage imageNamed:@"facebook"];
|
||||
}else if (type == DSWebMenuNotiType) {
|
||||
cell.avatarImageView.image = [UIImage imageNamed:@"noti"];
|
||||
cell.imgWidth.constant = 40;
|
||||
cell.avatarImageView.layer.cornerRadius = 20.f;
|
||||
cell.avatarImageView.layer.masksToBounds = YES;
|
||||
cell.avatarImageView.image = [UIImage imageNamed:@"noti2"];
|
||||
// cell.imgWidth.constant = 40;
|
||||
// cell.avatarImageView.layer.cornerRadius = 20.f;
|
||||
// cell.avatarImageView.layer.masksToBounds = YES;
|
||||
}
|
||||
}
|
||||
cell.avatarImageView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
@@ -127,7 +128,7 @@ static NSString *identifier = @"AvatarCollectionViewCell";
|
||||
|
||||
- (UIImage *)circularImageWithText:(NSString *)text {
|
||||
// 设置字体和大小
|
||||
UIFont *font = [UIFont systemFontOfSize:16.0f];
|
||||
UIFont *font = [UIFont boldSystemFontOfSize:15.0f];
|
||||
CGSize textSize = [text sizeWithFont:font];
|
||||
|
||||
// 创建图形上下文
|
||||
@@ -141,11 +142,11 @@ static NSString *identifier = @"AvatarCollectionViewCell";
|
||||
CGContextClip(context);
|
||||
|
||||
// 设置背景颜色(可选)
|
||||
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0); // 白色背景
|
||||
CGContextSetRGBFillColor(context, 228.0/255.0, 171.0/255.0, 95.0/255.0, 1.0); // 白色背景
|
||||
CGContextFillRect(context, rect);
|
||||
|
||||
// 设置文本颜色
|
||||
[[UIColor redColor] set];
|
||||
[[UIColor blackColor] set];
|
||||
|
||||
// 计算文本绘制位置,使其居中
|
||||
CGFloat x = (size - textSize.width) / 2.0f;
|
||||
|
||||
Reference in New Issue
Block a user