说实话,上面的效果用 Flutter 一个组件就完活了。iOS 原生的话还是得多敲几句代码的!话不多说,代码如下:
//
// CC_SelProView.m
// ScoPro
//
// Created by CC520 on 2024/1/17.
//
#import "CC_SelProView.h"
@implementation CC_SelProView
-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self){
[self setUI];
}
return self;
}
-(void)setUI{
UILabel *lab = [[UILabel alloc]init];
lab.text = @"定位/最近访问";
lab.font = FontSize(15);
lab.textColor = RGBCOLOR(156, 156, 156);
[self addSubview:lab];
[lab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(20);
make.left.mas_equalTo(15);
}];
UIView *locationView = [[UIView alloc]initWithFrame:CGRectMake(0, 45, SCREEN_WIDTH, 50)];
[self addSubview:locationView];
NSMutableArray *titleAry = [[NSMutableArray alloc]initWithObjects:@"河南省", @"黑龙江省", nil];
for (int i = 0; i < titleAry.count; i ++) {
CGFloat margin = 10;
CGFloat width = (SCREEN_WIDTH - margin * 5)/4;
CGFloat height = 35;
UIButton *button = [hTools createButtonWithImg:nil title:titleAry[i] titleColor:UIColor.blackColor font:15 backgroundColor:UIColor.whiteColor isClip:YES cornerRadius:5];
button.layer.borderColor = RGBCOLOR(195, 195, 195).CGColor;
button.layer.borderWidth = 1.0f;
button.frame = CGRectMake(15 + (margin + width)*i, 0, width, height);
[locationView addSubview:button];
if (i == 0){
[button setImage:[UIImage imageNamed:@"ze-location"] forState:UIControlStateNormal];
button.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
}
}
}
@end
零散知识点,仅做记录哈!