You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
3.5 KiB
94 lines
3.5 KiB
![]()
2 years ago
|
//
|
||
|
// AddWeekTableViewCell.m
|
||
|
// tongxin
|
||
|
//
|
||
|
// Created by WeiChaoZheng on 2018/7/4.
|
||
|
// Copyright © 2018年 xTT. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "AddWeekTableViewCell.h"
|
||
|
|
||
|
@interface AddWeekTableViewCell()
|
||
|
@property (strong, nonatomic) NSMutableArray *btnArr;
|
||
|
@end
|
||
|
@implementation AddWeekTableViewCell
|
||
|
|
||
|
- (void)awakeFromNib {
|
||
|
[super awakeFromNib];
|
||
|
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
||
|
self.aTitleLabel.font = DefineFontSize;
|
||
|
CGFloat btnWH = 27.0;
|
||
|
CGFloat viewWidth = SWIDTH - 65;
|
||
|
CGFloat btnY = (CGRectGetHeight(self.weekBtnView.frame)-btnWH) / 2.0;
|
||
|
//间隔 interval
|
||
|
CGFloat interval = (viewWidth-(27.0*7))/8.0 ;
|
||
|
self.btnArr = [NSMutableArray array];
|
||
|
for (int i = 0; i < 7; i++) { // 0~6
|
||
|
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
|
||
|
formatter.numberStyle = kCFNumberFormatterRoundHalfDown;
|
||
|
NSString *numberStr = [formatter stringFromNumber:[NSNumber numberWithInt:i+1]];
|
||
|
if([numberStr isEqualToString:@"七"]){
|
||
|
numberStr = @"日";
|
||
|
}
|
||
|
UIButton *button = [UIButton buttonWithType:0];
|
||
|
button.frame = CGRectMake(interval+(btnWH+interval)*i, btnY, btnWH, btnWH);
|
||
|
button.tag = 8080 + i;
|
||
|
[button setTitle:numberStr forState:0];
|
||
|
button.titleLabel.font = DefineFontSize;
|
||
|
button.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
||
|
[button setTitleColor:[UIColor blackColor] forState:0];
|
||
|
[button setBackgroundColor:[UIColor whiteColor]];
|
||
|
button.layer.cornerRadius = btnWH/2.0;
|
||
|
button.layer.masksToBounds = YES;
|
||
|
button.layer.borderWidth = 1;
|
||
|
button.layer.borderColor = RGB(240, 240, 240).CGColor;
|
||
|
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
|
||
|
[self.weekBtnView addSubview:button];
|
||
|
[self.btnArr addObject:button];
|
||
|
}
|
||
|
}
|
||
|
-(void)setWeek:(NSString *)weekStr{
|
||
|
self.weekStr = weekStr;
|
||
|
for (int i = 0; i < weekStr.length ; i++) {
|
||
|
NSString *str = [weekStr substringWithRange:NSMakeRange(i, 1)];
|
||
|
if([str intValue] == 1){
|
||
|
UIButton *tempBtn = self.btnArr[i];
|
||
|
int index = tempBtn.tag - 8080;
|
||
|
[tempBtn setTitleColor:[UIColor whiteColor] forState:0];
|
||
|
[tempBtn setBackgroundColor:mainColor];
|
||
|
tempBtn.selected = YES;
|
||
|
tempBtn.layer.borderColor = mainColor.CGColor;
|
||
|
self.weekStr = [self.weekStr stringByReplacingCharactersInRange:NSMakeRange(index, 1) withString:@"1"];
|
||
|
}
|
||
|
}
|
||
|
[self.contentView bringSubviewToFront:self.weekBtnView];
|
||
|
}
|
||
|
-(void)buttonAction:(UIButton*)sender{
|
||
|
sender.selected = !sender.selected;
|
||
|
int index = sender.tag - 8080;
|
||
|
NSString *status = @"0";
|
||
|
if(sender.selected){
|
||
|
status = @"1";
|
||
|
[sender setTitleColor:[UIColor whiteColor] forState:0];
|
||
|
[sender setBackgroundColor:mainColor];
|
||
|
sender.layer.borderColor = mainColor.CGColor;
|
||
|
}else{
|
||
|
status = @"0";
|
||
|
[sender setTitleColor:[UIColor blackColor] forState:0];
|
||
|
[sender setBackgroundColor:[UIColor whiteColor]];
|
||
|
sender.layer.borderColor = RGB(240, 240, 240).CGColor;
|
||
|
}
|
||
|
self.weekStr = [self.weekStr stringByReplacingCharactersInRange:NSMakeRange(index, 1) withString:status];
|
||
|
if(self.weekSelectBlack){
|
||
|
self.weekSelectBlack(self.weekStr);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
|
||
|
[super setSelected:selected animated:animated];
|
||
|
|
||
|
// Configure the view for the selected state
|
||
|
}
|
||
|
|
||
|
@end
|