JJLabel
有长按复制的功能,且在将要复制时和将要结束复制时皆有block事件,(此功能默认开启)代码如下:
JJLabel *copyLab = [[JJLabel alloc] init]; copyLab.frame = CGRectMake(20, 100, (superViewWidth - 20 * 2), 30); copyLab.text = @"阿杰说:这是被copy的内容,copy时会变蓝"; copyLab.textAlignment = NSTextAlignmentCenter; copyLab.subFromIndexString = @"阿杰说:"; copyLab.appendString = @"ajie"; [self.view addSubview:copyLab]; __weak __typeof(&*copyLab) weakLab = copyLab; copyLab.willShowMenu = ^(){ weakLab.textColor = [UIColor blueColor]; }; copyLab.willHiddenMenu = ^(){ weakLab.textColor = [UIColor blackColor]; };
可以非常简洁的设置行间距和字间距,并且容易的得到label的高度--isCopy 可以设置是否有复制功能
JJLabel *spaceLab = [[JJLabel alloc] init]; spaceLab.text = @"这是一个可以自定义行间距和字间距的label,并且可以直接获取到label的高度,大大提升了码农的工作效率"; spaceLab.numberOfLines = 0; spaceLab.lineSpace = 5.0f; spaceLab.characterSpace = 5.0f; spaceLab.isCopy = NO; CGFloat labHeight = [spaceLab getLableHeightWithMaxWidth:(superViewWidth - 30 * 2)]; spaceLab.frame = CGRectMake(30, 150, (superViewWidth - 30 * 2), labHeight); [self.view addSubview:spaceLab];
可以将label中第一次出现的某字段,改变字体大小和颜色
JJLabel *changeLab = [[JJLabel alloc] init]; changeLab.text = @"阿杰说:这是一个可以自定义行间距和字间距的label,并且可以直接获取到label的高度,大大提升了码农的工作效率"; changeLab.numberOfLines = 0; changeLab.isCopy = NO; JJLabelItem *item = [JJLabelItem new]; item.itemContent = @"阿杰说:"; item.itemColor = [UIColor orangeColor]; item.itemFont = [UIFont systemFontOfSize:30]; changeLab.changeArray = @[item]; CGFloat labHeight = [changeLab getLableHeightWithMaxWidth:(superViewWidth - 30 * 2)]; changeLab.frame = CGRectMake(30, 300, (superViewWidth - 30 * 2), labHeight); [self.view addSubview:changeLab];
资源在此 JJLabel