我有一个UITableView(Grouped!)并且需要计算两种样式的单元格的高度:UITableViewCellStyleDefault和UITableViewCellStyleValue2.
我就是这样做的UITableViewCellStyleDefault:
CGSize textSize = {300.f, 200000.0f};
CGSize size = [myTextString1 sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:textSize lineBreakMode:UILineBreakModeWordWrap];
size.height += 30.0f;
result = MAX(size.height, 44.0f);
Run Code Online (Sandbox Code Playgroud)
并为UITableViewCellStyleValue2:
CGSize textSize = {207.f, 200000.0f};
CGSize size = [myTextString2 sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:textSize lineBreakMode:UILineBreakModeWordWrap];
size.height += 30.0f;
result = MAX(size.height, 44.0f);
Run Code Online (Sandbox Code Playgroud)
我的问题是他们返回不正确的高度,我认为这是textSize我使用错误数字的地方.对于长文本,底部部分被缩短(通常只是一条带有几个单词的行),对于两个CellStyles,它们在单元格中的文本上方和下方都有奇怪的间距.
因为UITableViewCellStyleValue2我得到了宽度size(207.0f),使text.backgroundColor变为红色,然后只计算盒子的大小.300.0f宽度UITableViewCellStyleDefault是指细胞的大小UITableViewStyleGrouped.
有谁知道我需要使用哪些值来正确计算a的大小,NSString从而为我的细胞获得合适的高度?
谢谢
我有一个移动到视图中的UIView.2秒后,我想再次将UIView移出视野.我该怎么做呢?我试过下面的,但它不起作用:(
我已经设置了NSLog,但它看起来不像是完成然后调用loadingViewDisappear:方法:(
谢谢.
...
[UIView beginAnimations:@"AnimateIn" context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration: 0.7f];
[UIView setAnimationDidStopSelector:@selector(loadingViewDisappear:finished:context:)];
loadingView.frame = CGRectMake(rect.origin.x, rect.origin.y - 80, rect.size.width, rect.size.height);
[UIView commitAnimations];
}
- (void)loadingViewDisappear:(NSString *)animationID finished:(NSNumber *) finished context:(void *) context {
NSLog( (finished ? @"YES!" : @"NO!" ) );
if ([animationID isEqualToString:@"AnimateIn"] && finished) {
[UIView beginAnimations:@"AnimateOut" context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseIn];
[UIView setAnimationDelay:2.0f];
[UIView setAnimationDuration: 0.7f];
loadingView.frame = CGRectMake(0, 480, 320, 80);
[UIView commitAnimations];
[loadingView removeFromSuperview];
}
}
Run Code Online (Sandbox Code Playgroud) 我正在解析大量数据,我最初将其插入到核心数据存储中.
稍后,我正在解析相同的XML,尽管其中一些可能已经更新.然后我做的是检查具有相同标签的现有记录,如果已经存在,我用数据更新记录.
然而,虽然我的初始解析(约11.000条记录)需要8秒左右,但更新似乎很昂贵,需要144秒(这些是模拟器运行,因此在实际设备上显着更长).
虽然第一次很好(我正在显示一个进度条),但第二次是不可接受的长,我想做一些事情来提高速度(即使它发生在一个单独的线程的后台).
不幸的是,这不是查找或创建的问题,因为XML中的数据可能已针对单个记录进行了更改,因此每个人都可能需要更新.
我对属性进行了索引,这加快了初始解析和更新,但它仍然很慢(上面的数字是索引).我注意到解析/更新似乎逐渐减慢.虽然最初速度很快,但随着越来越多的记录被处理,它会越来越慢.
所以最后我的问题是,如果我有什么建议可以提高我更新数据集的速度?我正在使用MagicalRecord获取记录.这是代码:
Record *record;
if (!isUpdate) {
record = [NSEntityDescription insertNewObjectForEntityForName:@"Record" inManagedObjectContext:backgroundContext];
} else {
NSPredicate *recordPredicate = [NSPredicate predicateWithFormat:@"SELF.tag == %@", [[node attributeForName:@"tag"] stringValue]];
record = [Record findFirstWithPredicate:recordPredicate];
}
Run Code Online (Sandbox Code Playgroud) 无论如何我可以UINavigationBar在横向模式下设置标题的字体大小吗?
我正在使用UIAppearance代理来自定义标题文本属性,而我在横向时对字体大小特别感兴趣.它是纵向字体,但在旋转到横向时,字体大小不会缩小为默认行为.
[[UINavigationBar appearance] setTitleTextAttributes:[[NSDictionary alloc] initWithObjectsAndKeys:
[UIFont fontWithName:@"Awesome-Bold" size:20], UITextAttributeFont,
[UIColor colorWithWhite:0.0f alpha:0.2f], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f, -1.0f)], UITextAttributeTextShadowOffset,
[UIColor whiteColor], UITextAttributeTextColor,
nil]];
Run Code Online (Sandbox Code Playgroud)
不幸的是,我没有看到任何barMetric:财产setTitleAttributes:.
谢谢.
我一直在寻找任何一个示例代码,用于在弯曲的路径上绘制UILabel(或只是一个NSString或某个东西),但空手而归.
有没有人知道是否可以在弯曲的路径上绘制文字,如圆圈或其他东西,而不是为每一个字母使用单独的图形片段?
我还没有真正用Core Graphics做过多少编程.而且我倾向于坚持使用QuartzCore,因为它通过图层属性做了很多我需要的东西:)
但是,我有一个UIView,它目前是渐变的.我想为这个UIView添加圆角,当我绘制渐变时,layer属性不会这样做:
- (void)drawRect:(CGRect)rect {
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGGradientRef glossGradient;
CGColorSpaceRef rgbColorspace;
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
CGFloat components[8] = { 1.0, 1.0, 1.0, 0.95, // Start color
1.0, 1.0, 1.0, 0.60 }; // End color
rgbColorspace = CGColorSpaceCreateDeviceRGB();
glossGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);
CGRect currentBounds = self.bounds;
CGPoint topCenter = CGPointMake(CGRectGetMidX(currentBounds), 0.0f);
CGPoint midCenter = CGPointMake(CGRectGetMidX(currentBounds), CGRectGetMaxY(currentBounds));
CGContextDrawLinearGradient(currentContext, glossGradient, topCenter, midCenter, 0);
CGGradientRelease(glossGradient);
CGColorSpaceRelease(rgbColorspace);
}
Run Code Online (Sandbox Code Playgroud)
我不确定我应该在drawRect方法中舍入到哪里.谢谢.
我一直无法找到这个问题的答案.
我在UIScrollView中有一个UIImageView,我希望中心的内容是垂直的.
现在,我能够做到这一点的唯一方法是根据UIImageView大小的高度设置滚动视图的contentInset,但这不是一个完美的解决方案; 它只是增加了UIImageView的大小,使得UIScrollView'认为'它的内容更大,并将这些黑条添加到顶部.
我试图从以下方面获得帮助:
UIScrollView带有居中的UIImageView,就像Photos app一样
和
但是还没能用这些答案来解决它.
我没有那么多地使用NSDate,所以我想要一些帮助我正在做的计算.
我有一个整数,从午夜开始,我的商店的收盘时间是几分钟.基本上,我的商店在下午5点关闭,这给了我整数1020.
所以现在是10.45PM或22.45.从00:00开始的整数是1365,我可以这样说
if (storeHour < currentTime) {
// closed!
}
Run Code Online (Sandbox Code Playgroud)
但是,我不知道如何从"22.45"得到我从NSDate到将其转换为表示自00:00以来的时间的整数.NSDate中有什么东西可以帮助我吗?
谢谢
我有几个UITableViewController类,我只是注意到这些方法没有被调用:
-(void)viewWillAppear:(BOOL)animated;
-(void)viewDidAppear:(BOOL)animated;
Run Code Online (Sandbox Code Playgroud)
我在http://discussions.apple.com/thread.jspa?threadID=1529769&tstart=0中读到了我在推送视图控制器时必须自己调用这些方法,但这很奇怪,因为它适用于除UITableViewController之外的任何东西.
当我需要在推动UITableViewController的UIViewController中取消选择UITableViewCell时,这也是一个问题.
我有一个简单的UINavigationController.在init方法中,我创建并添加UITableView作为子视图.
- (id)init {
self = [super init];
if (self) {
NSLog(@"%@", NSStringFromCGRect(self.view.frame)); // {{0, 20}, {320, 460}}
tableView = [[UITableView alloc] initWithFrame:self.view.frame];
[self.view addSubview:tableView];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
我发现在处理新项目时我总是遇到同样恼人的问题.添加的子视图最终位于导航栏下方20个像素处.
为什么我最终以{{0,20},{320,460}}为self.view.frame?我不想强制使用CGRect框架,我宁愿根据视图控制器的框架进行设置,这样我就不会遇到动态框架更改的问题(网络共享,电话等等,状态栏更高) .
更新:还注意到我的框架高度为460.这也没有意义.在我的情况下,我实际上有一个标签栏,所以高度不应该减去状态栏,减去uinavigationbar并减去标签栏高度?
谢谢
iphone ×7
ios ×3
nsstring ×2
uitableview ×2
animation ×1
core-data ×1
curve ×1
frame ×1
gradient ×1
nsdate ×1
objective-c ×1
uiappearance ×1
uifont ×1
uiimageview ×1
uilabel ×1
uiscrollview ×1
uiview ×1