https://www.youtube.com/watch?v=ZqKbN_C4Yvg
课程影片约55分处
#import "TextStatsColorAndOutlineViewContrller.h"
@interface TextStatsColorAndOutlineViewContrller()
@property (weak, nonatomic) IBOutlet UILabel *colorfulCharacterLabel;
@property (weak, nonatomic) IBOutlet UILabel *outlineCharacterLabel;
@end
@implementation TextStatsColorAndOutlineViewContrller
-(void)setTextToAnalyze:(NSAttributedString *)textToAnalyze
{
_textToAnalyze = textToAnalyze;
if (self.view.window) [self updateUi];//如果是nil就不出现在萤幕上
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self updateUi];
}
-(void) updateUi
{
self.colorfulCharacterLabel.text = [[self characterWithAttribute:NSForegroundColorAttributeName] length];
self.outlineCharacterLabel.text = [[self characterWithAttribute:NSForegroundColorAttributeName] length];
}
-(NSAttributedString *)characterWithAttribute:(NSString *)attributeName
{
NSMutableAttributedString *characters = [[NSMutableAttributedString alloc ] init ];
int index = 0;
while (index < [self.textToAnalyze length]) {
NSRange range;
id value = [self.textToAnalyze attribute:attributeName atIndex:index effectiveRange: &range];
if (value) {
[characters appendAttributedString:[self.textToAnalyze attributedSubstringFromRange:range]];
index = range.location + range.length;
}
else{
index++;
}
}
return characters;
}
警告讯息:
在index = range.location + range.length;这一行
implicit conversion loses integer precision 'unsigned long' to 'int'
我的Code都照打
怎么还是会有warninghttps://www.youtube.com/watch?v=ZqKbN_C4Yvg
课程影片约55分处
#import "TextStatsColorAndOutlineViewContrller.h"
@interface TextStatsColorAndOutlineViewContrller()
@property (weak, nonatomic) IBOutlet UILabel *colorfulCharacterLabel;
@property (weak, nonatomic) IBOutlet UILabel *outlineCharacterLabel;
@end
@implementation TextStatsColorAndOutlineViewContrller
-(void)setTextToAnalyze:(NSAttributedString *)textToAnalyze
{
_textToAnalyze = textToAnalyze;
if (self.view.window) [self updateUi];//如果是nil就不出现在萤幕上
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self updateUi];
}
-(void) updateUi
{
self.colorfulCharacterLabel.text = [[self characterWithAttribute:NSForegroundColorAttributeName] length];
self.outlineCharacterLabel.text = [[self characterWithAttribute:NSForegroundColorAttributeName] length];
}
-(NSAttributedString *)characterWithAttribute:(NSString *)attributeName
{
NSMutableAttributedString *characters = [[NSMutableAttributedString alloc ] init ];
int index = 0;
while (index < [self.textToAnalyze length]) {
NSRange range;
id value = [self.textToAnalyze attribute:attributeName atIndex:index effectiveRange: &range];
if (value) {
[characters appendAttributedString:[self.textToAnalyze attributedSubstringFromRange:range]];
index = range.location + range.length;
}
else{
index++;
}
}
return characters;
}
警告讯息:
在index = range.location + range.length;这一行
implicit conversion loses integer precision 'unsigned long' to 'int'
我的Code都照打
怎么还是会有warning....
不解QQ