如何从新的iOS 7方法sizeWithAttributes返回多行文本CGSize?
我希望这能产生与sizeWithFont:constrainedToSize相同的结果.
NSString *text = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus eu urna quis lacus imperdiet scelerisque a nec neque. Mauris eget feugiat augue, vitae porttitor mi. Curabitur vitae sollicitudin augue. Donec id sapien eros. Proin consequat tellus in vehicula sagittis. Morbi sed felis a nibh hendrerit hendrerit. Lorem ipsum dolor sit."
CGSize textSize = [text sizeWithAttributes:@{ NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Light" size:16.0] }];
Run Code Online (Sandbox Code Playgroud)
此方法仅生成单行文本的高度.
我目前正在创建一个使用自定义View Controller容器的应用程序.屏幕上一次显示多个视图,当点击一个视图时,所选视图控制器将动画显示为全屏.在这样做时,所选视图控制器子视图也会缩放(帧,字体大小等).但是,UILabel的字体属性不可动画导致问题.我尝试过多种解决方案,但都很糟糕.
我尝试过的解决方案是:
到目前为止,一个是最好的解决方案,但我不满意.
我正在寻找其他建议,如果有人有任何或UILabel替代使用[UIView animate ..]平滑动画.
这是一个很好的例子,类似于我想要的UILabel:http: //www.cocoawithlove.com/2010/09/zoomingviewcontroller-to-animate-uiview.html
编辑:此代码有效
// Load View
self.label = [[UILabel alloc] init];
self.label.text = @"TEXT";
self.label.font = [UIFont boldSystemFontOfSize:20.0];
self.label.backgroundColor = [UIColor clearColor];
[self.label sizeToFit];
[self.view addSubview:self.label];
// Animation
self.label.font = [UIFont boldSystemFontOfSize:80.0];
self.label.transform = CGAffineTransformScale(self.label.transform, .25, .25);
[self.label sizeToFit];
[UIView animateWithDuration:1.0 animations:^{
self.label.transform = CGAffineTransformScale(self.label.transform, 4.0, 4.0);
self.label.center = self.view.center;
} completion:^(BOOL finished) {
self.label.font = [UIFont boldSystemFontOfSize:80.0];
self.label.transform = CGAffineTransformScale(self.label.transform, 1.0, 1.0);
[self.label sizeToFit];
}];
Run Code Online (Sandbox Code Playgroud) 我目前正在使用paperclip将图像上传到我的rails应用程序.这可能是一个非常简单的修复,但我如何或在何处保存丢失的图像?这是由于没有任何丢失图像而产生的错误.我该如何改变?
ActionController::RoutingError (No route matches "/photos/normal/missing.png"):
Run Code Online (Sandbox Code Playgroud) 我需要获取我创建的列表并找到最接近的两个点并打印出来.如何比较列表中的每个点?
没有任何需要绘图或任何东西,只需比较点并找到列表中最接近的两个.
import math # 'math' needed for 'sqrt'
# Distance function
def distance(xi,xii,yi,yii):
sq1 = (xi-xii)*(xi-xii)
sq2 = (yi-yii)*(yi-yii)
return math.sqrt(sq1 + sq2)
# Run through input and reorder in [(x, y), (x,y) ...] format
oInput = ["9.5 7.5", "10.2 19.1", "9.7 10.2"] # Original input list (entered by spacing the two points).
mInput = [] # Manipulated list
fList = [] # Final list
for o in oInput:
mInput = o.split()
x,y = float(mInput[0]), float(mInput[1])
fList += [(x, …
Run Code Online (Sandbox Code Playgroud) 如何才能使提交产品至少需要两个选项记录?
class Product < ActiveRecord::Base
belongs_to :user
has_many :options, :dependent => :destroy
accepts_nested_attributes_for :options, :allow_destroy => :true, :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
validates_presence_of :user_id, :created_at
validates :description, :presence => true, :length => {:minimum => 0, :maximum => 500}
end
class Option < ActiveRecord::Base
belongs_to :product
validates :name, :length => {:minimum => 0, :maximum => 60}
end
Run Code Online (Sandbox Code Playgroud) 如何以与iOS音乐应用程序相同的方式搜索iPod库?我想做一般查询,返回每个艺术家,专辑和歌曲的结果.例如,如果我搜索Kenny Chesney,我希望歌曲查询返回所有Kenny Chesney歌曲(以及包含Kenny Chesney的任何歌曲标题或专辑.)当我为每个属性(歌曲标题,专辑)创建此查询和谓词时标题,艺术家姓名),一个空数组返回.
这里有一些代码可以让您更好地了解我想要实现的目标:
MPMediaPropertyPredicate *songPredicate =
[MPMediaPropertyPredicate predicateWithValue:searchText
forProperty:MPMediaItemPropertyTitle
comparisonType:MPMediaPredicateComparisonContains];
MPMediaPropertyPredicate *albumPredicate =
[MPMediaPropertyPredicate predicateWithValue:searchText
forProperty:MPMediaItemPropertyAlbumTitle
comparisonType:MPMediaPredicateComparisonContains];
MPMediaPropertyPredicate *artistPredicate =
[MPMediaPropertyPredicate predicateWithValue:searchText
forProperty:MPMediaItemPropertyArtist
comparisonType:MPMediaPredicateComparisonContains];
MPMediaQuery *songsQuery = [MPMediaQuery songsQuery];
[songsQuery addFilterPredicate:songNamePredicate];
[songsQuery addFilterPredicate:artistNamePredicate];
[songsQuery addFilterPredicate:albumNamePredicate];
NSLog(@"%@", [songsQuery items]);
Run Code Online (Sandbox Code Playgroud)
我有这个工作通过分别运行每个谓词的查询,但这似乎非常低效!
我目前正在使用a UILabel
来显示多行文本.断行最多设置为,NSLineBreakByWordWrapping
因此标签会自动插入换行符.如何检测这些换行符的位置?基本上,我想返回包含每个\n
中断的字符串.
我目前正在开发一个专门针对iOS7的应用程序,它利用菜单中打开的UIDocumentInteractionController,需要一个方法,当用户取消并且不选择可用选项时通知我.
UIDocumentInteractionControllerDelegate提供:
- (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *) controller
Run Code Online (Sandbox Code Playgroud)
但这并未指定用户是否点按了其中一个可用选项或取消.
有任何想法吗?
我刚刚升级到rails 3,但在升级之前运行了ruby 1.9.1.Rails 3不支持Ruby 1.9.1.我怎样才能降级到ruby 1.8.7?
当我从History Core Data对象记录/请求值时,以下代码返回以下错误:
-[CFNumber release]: message sent to deallocated instance 0x17ea2a90
Run Code Online (Sandbox Code Playgroud)
我原本以为其他地方有一个问题,并花了无数个小时试图调试这个没有运气.在进一步测试之后,我已经确定崩溃是从History Core Data对象请求某些值.任何人都可以看到为什么对象值被解除分配的任何问题?
[[DocumentHandler sharedDocumentHandler] performWithDocument:^(UIManagedDocument *document) {
if(!self.document) {
self.document = document;
}
__block NSString *identifier = [[NSUserDefaults standardUserDefaults] objectForKey:kUserDefaultsUserIdentifier];
[self.document.managedObjectContext performBlock:^{
// Create history object
History *history = [NSEntityDescription insertNewObjectForEntityForName:@"History"
inManagedObjectContext:self.document.managedObjectContext];
history.identifier = identifier;
history.followers = [NSNumber numberWithInteger:53];
history.following = [NSNumber numberWithInteger:53];
history.newFollowers = [NSNumber numberWithInteger:53];
history.unfollowers = [NSNumber numberWithInteger:53];
history.fans = [NSNumber numberWithInteger:53];
history.mutualFriends = [NSNumber numberWithInteger:53];
history.nonFollowers = [NSNumber numberWithInteger:53];
[self.document saveToURL:self.document.fileURL forSaveOperation:UIDocumentSaveForOverwriting completionHandler:^(BOOL success) …
Run Code Online (Sandbox Code Playgroud) ios ×4
iphone ×3
ios7 ×2
objective-c ×2
uilabel ×2
activerecord ×1
animation ×1
associations ×1
cocoa-touch ×1
core-data ×1
crash ×1
line-breaks ×1
math ×1
mpmediaitem ×1
mpmediaquery ×1
nsstring ×1
paperclip ×1
python ×1
ruby ×1
validation ×1