pragma mark - 重畫(huà)tableview的線
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
CGContextFillRect(context, rect);
//下分割線
CGContextSetStrokeColorWithColor(context, [UIColor lightGrayColor].CGColor);
CGContextStrokeRect(context, CGRectMake(0, rect.size.height, rect.size.width, 1));
}
pragma mark - 如何給UILabel添加中線
UILabel * strikeLabel = [[UILabel alloc] initWithFrame:(CGRectMake(10, 10, 50, 30))];
NSString *textStr = [NSString stringWithFormat:@"%@元", primeCost];
//中劃線
NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:textStr attributes:attribtDic];
// 賦值
strikeLabel.attributedText = attribtStr;
[self.view addSubview:strikeLabel];
pragma mark - 如何給UILabel添加下劃線
UILabel *underlineLabel = [[UILabel alloc] initWithFrame:(CGRectMake(10, 10, 50, 30))];
NSString *textStr = [NSString stringWithFormat:@"%@元", primeCost];
// 下劃線
NSDictionary *attribtDic = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:textStr attributes:attribtDic];
//賦值
underlineLabel.attributedText = attribtStr;
[self.view addSubview:underlineLabel];
pragma mark - 創(chuàng)建Button下劃線
UIButton *button = [[UIButtonalloc]initWithFrame:CGRectMake(0,0, KScreenWidth,25)];
[button setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
[button setBackgroundColor:[UIColorcolorWithRed:239.0/255.0green:152.0/255.0blue:121.0/255.0alpha:1]];
[button.titleLabel setFont:[UIFont systemFontOfSize:10]];
NSMutableAttributedString *title = [[NSMutableAttributedStringalloc] initWithString:@"號(hào)源緊俏經(jīng)常預(yù)約不上贪磺?試試預(yù)約搶號(hào)功能快压? >>"];
NSRange titleRange = {0, [titlelength]};
[title addAttribute:NSUnderlineStyleAttributeNamevalue:[NSNumbernumberWithInteger:NSUnderlineStyleSingle]range:titleRange];
[button setAttributedTitle:titleforState:UIControlStateNormal];
[button addTarget:selfaction:@selector(buttonAction:)forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者