-(void)createIndexUIWithView:(UIView *)view{
UIView *row1 = [UIView
new
];
UIView *row2 = [UIView
new
];
UIView *row3 = [UIView
new
];
UIView *row4 = [UIView
new
];
[view addSubview:row1];
[view addSubview:row2];
[view addSubview:row3];
[view addSubview:row4];
[row1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.and.left.equalTo(view);
make.height.equalTo(view.mas_height).multipliedBy(0.25);
make.top.equalTo(view.mas_top);
}];
[row2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.and.left.equalTo(view);
make.top.equalTo(row1.mas_bottom);
make.height.equalTo(view.mas_height).multipliedBy(0.25);
}];
[row3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(view.mas_right);
make.top.equalTo(row2.mas_bottom);
make.height.equalTo(view.mas_height).multipliedBy(0.25);
make.left.equalTo(view.mas_left);
}];
[row4 mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.and.left.equalTo(view);
make.top.equalTo(row3.mas_bottom);
make.height.equalTo(view.mas_height).multipliedBy(0.25);
}];
[self createIndexRowUI:PlantReferenceWaterIndex withUIView:row1];
[self createIndexRowUI:PlantReferenceSumIndex withUIView:row2];
[self createIndexRowUI:PlantReferenceTemperatureIndex withUIView:row3];
[self createIndexRowUI:PlantReferenceElectrolyteIndex withUIView:row4];
}
-(void)createIndexRowUI:(PlantReferenceIndex) index withUIView:(UIView *)view{
UILabel *indexTitle = [UILabel
new
];
indexTitle.font = [UIFont fontWithName:@
"HeiTi SC"
size:14];
indexTitle.textColor = [UIColor colorWithWhite:0.326 alpha:1.000];
[view addSubview:indexTitle];
[indexTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(view.mas_left).
with
.offset(20);
make.centerY.equalTo(view.mas_centerY);
}];
switch
(index) {
case
PlantReferenceWaterIndex:
{
indexTitle.text = @
"水分"
;
UIImageView * current;
for
(int i=1;i<=5;i++){
if
(i<_reference.waterIndex){
current = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@
"icon_water_light"
]];
}
else
{
current = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@
"icon_water_dark"
]];
}
[view addSubview:current];
[current mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(view.mas_right).
with
.multipliedBy(0.12*(i-1) +0.3);
make.centerY.equalTo(view.mas_centerY);
}];
}
}
break
;
case
PlantReferenceSumIndex:
{
indexTitle.text = @
"光照"
;
UIImageView * current;
for
(int i=1;i<=5;i++){
if
(i<_reference.temperatureIndex){
current = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@
"icon_summer_light"
]];
}
else
{
current = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@
"icon_summer_dark"
]];
}
[view addSubview:current];
[current mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(view.mas_right).
with
.multipliedBy(0.12*(i-1) +0.3);
make.centerY.equalTo(view.mas_centerY);
}];
}
}
break
;
case
PlantReferenceTemperatureIndex:
{
indexTitle.text = @
"温度"
;
UIImageView * current;
for
(int i=1;i<=5;i++){
if
(i<_reference.sumIndex){
current = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@
"icon_temperature_light"
]];
}
else
{
current = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@
"icon_temperature_dark"
]];
}
[view addSubview:current];
[current mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(view.mas_right).
with
.multipliedBy(0.12*(i-1) +0.3);
make.centerY.equalTo(view.mas_centerY);
}];
}
}
break
;
case
PlantReferenceElectrolyteIndex:
{
indexTitle.text = @
"肥料"
;
UIImageView * current;
for
(int i=1;i<=5;i++){
if
(i<_reference.electrolyteIndex){
current = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@
"icon_electolyte_light"
]];
}
else
{
current = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@
"icon_electolyte_dark"
]];
}
[view addSubview:current];
[current mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(view.mas_right).
with
.multipliedBy(0.12*(i-1) +0.3);
make.centerY.equalTo(view.mas_centerY);
}];
}
}
break
;
default
:
break
;
}
}
-(void)createUI{
self.title = _reference.name;
UIView *titleView = [UIView
new
];
UIView *caredView = [UIView
new
];
[self.view addSubview:caredView];
UITextView *brifeView = [UITextView
new
];
[self.view addSubview:brifeView];
self.view.backgroundColor = [UIColor colorWithWhite:0.965 alpha:1.000];
UIImageView *plantThrm = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@
"defalutPlantReferenceIcon"
]];
[self.view addSubview:plantThrm];
[plantThrm mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.top.equalTo(self.view).
with
.offset(10);
}];
[self.view addSubview:titleView];
UIImageView *bgTitleView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@
"bg-plant-reference-title"
]];
[titleView addSubview:bgTitleView];
[titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view.mas_right);
make.left.equalTo(plantThrm.mas_right).
with
.offset(20);
make.centerY.equalTo(plantThrm.mas_centerY);
}];
[bgTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(titleView);
}];
UILabel *title = [[UILabel alloc]init];
title.textColor = [UIColor whiteColor];
title.font = [UIFont fontWithName:@
"Heiti SC"
size:26];
title.text = _reference.name;
[titleView addSubview:title];
[title mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(titleView.mas_left).offset(10);
make.width.equalTo(titleView.mas_width);
make.centerY.equalTo(titleView.mas_centerY);
}];
UILabel *caredTitle = [[UILabel alloc]init];
caredTitle.textColor = [UIColor colorWithRed:0.172 green:0.171 blue:0.219 alpha:1.000];
caredTitle.font = [UIFont fontWithName:@
"Heiti SC"
size:10];
caredTitle.text = @
"植物养护"
;
[self.view addSubview:caredTitle];
[caredTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(plantThrm.mas_bottom).
with
.offset(20);
make.left.and.right.equalTo(self.view).
with
.offset(10);
make.height.mas_equalTo(10);
}];
[self createIndexUIWithView:caredView];
caredView.layer.cornerRadius = 5;
caredView.layer.masksToBounds = YES;
caredView.layer.borderWidth = 1;
caredView.layer.borderColor = [[UIColor colorWithWhite:0.521 alpha:1.000] CGColor];
caredView.backgroundColor = [UIColor whiteColor];
[caredView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(caredTitle.mas_bottom).
with
.offset(5);
make.left.equalTo(self.view.mas_left).
with
.offset(10);
make.right.equalTo(self.view.mas_right).
with
.offset(-10);
make.height.equalTo(brifeView);
}];
UILabel *brifeTitle = [[UILabel alloc]init];
brifeTitle.textColor = [UIColor colorWithRed:0.172 green:0.171 blue:0.219 alpha:1.000];
brifeTitle.font = [UIFont fontWithName:@
"Heiti SC"
size:10];
brifeTitle.text = @
"植物简介"
;
[self.view addSubview:brifeTitle];
[brifeTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(caredView.mas_bottom).
with
.offset(20);
make.left.and.right.equalTo(self.view).
with
.offset(10);
make.height.mas_equalTo(10);
}];
brifeView.layer.cornerRadius = 5;
brifeView.layer.masksToBounds = YES;
brifeView.layer.borderWidth = 1;
brifeView.layer.borderColor = [[UIColor colorWithWhite:0.447 alpha:1.000] CGColor];
brifeView.backgroundColor = [UIColor whiteColor];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
paragraphStyle.lineHeightMultiple = 20.f;
paragraphStyle.maximumLineHeight = 25.f;
paragraphStyle.minimumLineHeight = 15.f;
paragraphStyle.alignment = NSTextAlignmentJustified;
NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:12], NSParagraphStyleAttributeName:paragraphStyle, NSForegroundColorAttributeName:[UIColor colorWithWhite:0.447 alpha:1.000]};
brifeView.attributedText = [[NSAttributedString alloc] initWithString: _reference.brief attributes:attributes];
[brifeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(brifeTitle.mas_bottom).
with
.offset(5);
make.left.equalTo(self.view.mas_left).
with
.offset(10);
make.right.equalTo(self.view.mas_right).
with
.offset(-10);
make.bottom.equalTo(self.view.mas_bottom).
with
.offset(-10);
make.height.equalTo(caredView);
}];
}