电子说
简单讲就是需要开发用代码一步一步进行布局,这个过程需要开发全程参与。
开发前请熟悉鸿蒙开发指导文档:[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
ObjectiveC
复制代码
UIView *cardView = [[UIView alloc] init];
cardView.backgroundColor = [UIColor whiteColor];
cardView.layer.cornerRadius = 16;
cardView.clipsToBounds = YES;
[self.view addSubview:cardView];
[cardView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.right.mas_offset(-16);
make.height.mas_equalTo(116);
make.top.mas_equalTo(100);
}];
NSString *imgUrl = @"https://ke-image.ljcdn.com//110000-inspection//pc1_nBllrJgGj_1.jpg.280x210.jpg";
UIImageView *imgView = [[UIImageView alloc] init];
imgView.backgroundColor = [UIColor lightGrayColor];
[imgView sd_setImageWithURL:[NSURL URLWithString:imgUrl]];
[cardView addSubview:imgView];
[imgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.mas_offset(0);
make.left.mas_equalTo(0);
make.width.mas_equalTo(107);
}];
UILabel *titleLbl = [[UILabel alloc] init];
titleLbl.font = [UIFont systemFontOfSize:14 weight:UIFontWeightBold];
titleLbl.textColor = [UIColor blackColor];
titleLbl.text = @"万柳书院新一区 南北向满五唯一";
[cardView addSubview:titleLbl];
[titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(imgView.mas_right).mas_offset(12);
make.right.mas_offset(-12);
make.top.mas_equalTo(16);
}];
UILabel *subTitleLbl = [[UILabel alloc] init];
subTitleLbl.textColor = [UIColor blackColor];
subTitleLbl.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
subTitleLbl.text = @"4室2厅/278.35㎡/南 北/万柳书院";
[cardView addSubview:subTitleLbl];
[subTitleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(titleLbl);
make.top.mas_equalTo(titleLbl.mas_bottom).mas_offset(8);
}];
UILabel *priceLbl = [[UILabel alloc] init];
priceLbl.font = [UIFont systemFontOfSize:14 weight:UIFontWeightBold];
priceLbl.textColor = [UIColor redColor];
priceLbl.text = @"4238万";
[cardView addSubview:priceLbl];
[priceLbl mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(titleLbl);
make.bottom.mas_offset(-16);
}];
UILabel *avgPriceLbl = [[UILabel alloc] init];
avgPriceLbl.textColor = [UIColor lightGrayColor];
avgPriceLbl.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
avgPriceLbl.text = @"155,445元/平";
[cardView addSubview:avgPriceLbl];
[avgPriceLbl mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(priceLbl.mas_right).mas_offset(2);
make.right.mas_lessThanOrEqualTo(titleLbl.mas_right);
make.bottom.mas_equalTo(priceLbl);
}];
声明式则是由开发使用语言描述UI页面长什么样子,之后全权交给引擎去做
比如上面的卡片可以进行如下的拆分
TypeScript
复制代码
< View
style={{
borderRadius: 8,
marginHorizontal: 16,
flexDirection: 'row',
backgroundColor: 'white',
overflow: 'hidden',
height: 116,
}} >
< Image
source={{
uri: 'https://ke-image.ljcdn.com//110000-inspection//pc1_nBllrJgGj_1.jpg.280x210.jpg',
}}
style={{width: 107, backgroundColor: '#eee'}}
/ >
< View
style={{
marginVertical: 16,
marginHorizontal: 12,
flex: 1,
justifyContent: 'space-between',
}} >
< View >
< Text style={{fontSize: 14, color: '#222', fontWeight: '500'}} >
万柳书院新一区 南北向满五唯一
< /Text >
< Text style={{fontSize: 11, color: '#222', marginTop: 8}} >
4室2厅/278.35㎡/南 北/万柳书院
< /Text >
< /View >
< View
style={{flexDirection: 'row', marginTop: 8, alignItems: 'flex-end'}} >
< Text
style={{
fontSize: 17,
color: '#E62222',
fontWeight: 'bold',
}} >
4238万
< /Text >
< Text style={{fontSize: 11, color: '#999', marginLeft: 6}} >
155,445元/平
< /Text >
< /View >
< /View >
< /View >
flutter
复制代码
swift
复制代码
HStack(spacing:0) {
AsyncImage(url: URL(string: "https://ke-image.ljcdn.com//110000-inspection//pc1_nBllrJgGj_1.jpg.280x210.jpg"))
.frame(width:107)
.aspectRatio(contentMode: .fill)
.clipped()
VStack(alignment: .leading,
spacing:0) {
VStack(alignment: .leading,
spacing:0) {
Text("万柳书院新一区 南北向满五唯一")
.lineLimit(1)
.font(.system(size: 14))
.foregroundColor(.black)
.fontWeight(.bold)
Text("4室2厅/278.35㎡/南 北/万柳书院")
.lineLimit(1)
.font(.system(size: 12))
.foregroundColor(.black)
.padding(.top, 8)
}
Spacer()
HStack(alignment: .bottom,
spacing:2) {
Text("4238万")
.font(.system(size: 14))
.foregroundColor(.red)
.fontWeight(.bold)
Text("155,445元/平")
.font(.system(size: 12))
.foregroundColor(.secondary)
.padding(.leading, 2)
}
}
.padding(.vertical, 16)
.padding(.horizontal, 12)
Spacer()
}
.frame(height: 116)
.background(.white)
.clipShape(RoundedRectangle(cornerRadius: 8))
.padding(.horizontal, 16)
}
typescript
复制代码
Row() {
Row() {
Image("https://ke-image.ljcdn.com//110000-inspection//pc1_nBllrJgGj_1.jpg.280x210.jpg")
.width(107)
.height("100%")
.objectFit(ImageFit.Cover)
Column() {
Column() {
Text("柳书院新一区 南北向满五唯一")
.fontSize(16)
.fontColor("#222")
.maxLines(1)
Text("4室2厅/278.35㎡/南 北/万柳书院")
.fontSize(14)
.fontColor("#222")
.maxLines(1)
.margin({ top: 8 })
}
.alignItems(HorizontalAlign.Start)
Row() {
Text("4238万")
.fontSize(15)
.fontColor("#E62222")
.fontWeight(FontWeight.Bold)
Text("155,445元/平")
.fontSize(13)
.fontColor("#222")
.margin({ left: 2 })
}
.justifyContent(FlexAlign.Start)
.alignItems(VerticalAlign.Bottom)
}
.width("100%")
.height("100%")
.padding({ top: 16, bottom: 16, left: 12, right: 12 })
.alignItems(HorizontalAlign.Start)
.justifyContent(FlexAlign.SpaceBetween)
}
.borderRadius(8)
.margin({ left: 16, right: 16 })
.backgroundColor(Color.White)
.justifyContent(FlexAlign.Start)
.clip(true)
}
.height(116)
.width("100%")
`HarmonyOS与OpenHarmony鸿蒙文档籽料:mau123789是v直接拿`
审核编辑 黄宇
全部0条评论
快来发表一下你的评论吧 !