【发布时间】:2017-01-09 10:04:19
【问题描述】:
我是 iOS 新手,我遇到了关于动画图像与 marque 标签相同的问题。我正在为 UILabel 文本设置动画,为此我的代码是这样的
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
scrolllbl = [[UILabel alloc]initWithFrame:CGRectMake(0,0,scrolllbl.bounds.size.width, 1800)];
NSString *theText = @"A long string";
CGRect labelRect = CGRectMake(10, 50, 300, 50);
scrolllbl.adjustsFontSizeToFitWidth = YES;
[scrolllbl setNumberOfLines:0];
CGFloat fontSize = 30;
while (fontSize > 0.0)
{
CGSize size = [theText sizeWithFont:[UIFont fontWithName:@"Verdana" size:fontSize] constrainedToSize:CGSizeMake(labelRect.size.width, 10000) lineBreakMode:NSLineBreakByWordWrapping];
if (size.height <= labelRect.size.height) break;
fontSize -= 1.0;
}
//set font size
scrolllbl.font = [UIFont fontWithName:@"Arial" size:fontSize];
}
else
{
scrolllbl = [[UILabel alloc]initWithFrame:CGRectMake(0,0,scrolllbl.bounds.size.width, 800)];
// scrolllbl.textColor = [UIColor redColor];
}
//lbl2.text=result1;
NSLog(@"Result Array =%@",shortnamearray);
CGFloat y = 10;
NSMutableArray* animals = [NSMutableArray new];
NSUInteger maxCount = headarray.count > shortnamearray.count ? headarray.count : shortnamearray.count;
for (int i = 0; i < maxCount; i ++) {
if ([headarray objectAtIndex:i]) {
[animals addObject:[headarray objectAtIndex:i]];
}
if ([shortnamearray objectAtIndex:i]) {
[animals addObject:[shortnamearray objectAtIndex:i]];
}
}
NSLog(@"Array is =%@",animals);
for(int i=0;i<[shortnamearray count] && i<[headarray count];i++){
// y+=20;
y+=10;
NSString *newArray =[animals objectAtIndex:i];
newArray=[animals componentsJoinedByString:@""];
NSString *NewString;
[scrolllbl setLineBreakMode:NSLineBreakByWordWrapping];
scrolllbl.textAlignment = NSTextAlignmentCenter;
//[scrolllbl setText:NewString];
NSString * htmlString = @"<html><body>";
NSString *htmlString2=@"</body></html>";
NewString=[NSString stringWithFormat:@"%@%@%@",htmlString,newArray,htmlString2];
NSLog(@"New String =%@",NewString);
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[NewString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
scrolllbl.attributedText = attrStr;
NSString *theText = @"A long string";
CGRect labelRect = CGRectMake(10, 50, 300, 50);
scrolllbl.adjustsFontSizeToFitWidth = YES;
[scrolllbl setNumberOfLines:0];
CGFloat fontSize = 15;
while (fontSize > 0.0)
{
CGSize size = [theText sizeWithFont:[UIFont fontWithName:@"Verdana" size:fontSize] constrainedToSize:CGSizeMake(labelRect.size.width, 10000) lineBreakMode:NSLineBreakByWordWrapping];
if (size.height <= labelRect.size.height) break;
fontSize -= 1.0;
}
//set font size
scrolllbl.font = [UIFont fontWithName:@"Arial" size:fontSize];
}
NSTimer *timer = [NSTimer timerWithTimeInterval:1
target:self
selector:@selector(timer)
userInfo:nil
repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
//[_scrollView scrollRectToVisible:NSMakeRange(0,0,0.0) animated:YES];
[newsscroll addSubview:scrolllbl];
[UIView commitAnimations];
scroll.contentSize=CGSizeMake(newsscroll.frame.size.width+[shortnamearray count], scrolllbl.frame.size.height);
这就是我为 UILabel 做的事情。请给我建议如何为 UIImage 做。我的主要问题是根据来自网络服务的数据,图像可以是多个图像。提前致谢!
【问题讨论】:
-
使用 UICollectionView 来满足您对多个 i,age 的要求,并带有标记效果。
-
@CodeChanger 如何在其中添加标记效果?
标签: ios objective-c uiimage uilabel