计算字体大小以适应框架 – 核心文本 – NSAttributedString – iOS

我有一些文本,我正在通过NSAttributedString(下面的代码)绘制到一个固定的框架。 目前我很难将文字大小编码为16.我的问题是,有没有一种方法可以计算给定帧的文本的最佳拟合大小? – (void)drawText:(CGContextRef)contextP startX:(float)x startY:(float) y withText:(NSString *)standString { CGContextTranslateCTM(contextP, 0, (bottom-top)*2); CGContextScaleCTM(contextP, 1.0, -1.0); CGRect frameText = CGRectMake(1, 0, (right-left)*2, (bottom-top)*2); NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc] initWithString:standString]; [attrString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Bold" size:16.0] range:NSMakeRange(0, attrString.length)]; CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)(attrString)); struct CGPath * p = CGPathCreateMutable(); CGPathAddRect(p, NULL, frameText); CTFrameRef frame = CTFramesetterCreateFrame(framesetter, […]

iOS – UITapGestureRecognizer – 带参数的select器

在我的应用程序中,我在运行时dynamic添加图像到我的视图。 我可以在屏幕上同时显示多个图像。 每个图像都是从一个对象中加载的。 我已经添加了一个tapGestureRecongnizer的图像,以便当我点击它时调用适当的方法。 UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)]; [plantImageView addGestureRecognizer:tapGesture]; 我的问题是,我不知道我已经挖掘了什么形象。 我知道我可以打电话tapGestureRecognizer.location获得屏幕上的位置,但那对我来说并不是那么好。 理想情况下,我希望能够将图像加载的对象从轻击手势中传递出去。 但是,似乎我只能通过select器名称“imageTapped:”而不是它的参数。 – (IBAction)imageTapped:(Plant *)plant { [self performSegueWithIdentifier:@"viewPlantDetail" sender:plant]; } 有没有人知道一种方式,我可以通过我的对象作为参数到tapGestureRecongnizer或任何其他方式,我可以得到它的处理? 谢谢 布赖恩

如何在Safari浏览器中打开url,而不是在webview中

我想在safari中打开一个url,outisde的应用程序,而不是在web视图。 我实现了UIWebViewDelegate,但我仍然无法打开url。 基本上我无法点击url。 以下是代码: -(void)newView:(NSString *)title Description:(NSString *)desc URL:(NSString *)url{ webView =[[UIWebView alloc]initWithFrame:CGRectMake(15, 17, 190, 190)]; webView.backgroundColor=[UIColor clearColor]; webView.delegate=self; webView.opaque = NO; [webView loadHTMLString:[NSString stringWithFormat:@"<html><body p style='color:white' text=\"#FFFFFF\" face=\"Bookman Old Style, Book Antiqua, Garamond\" size=\"5\">%@ %@</body></html>", desc,url] baseURL:nil]; v = [[HUDView alloc] initWithFrame:CGRectMake(60, 70, 220, 220)]; cancelButton = [UIButton buttonWithType:UIButtonTypeCustom]; cancelButton.frame = CGRectMake(0, 0, 30, […]

NSPredicate在关系实体内进行search

我有一个名为Band的实体,它与Category实体有多对多的关系。 Category实体只包含一个categoryNamestring属性。 一个例子logging: Band: bandName: Kiss bandCategories: – > BandCategory:categoryName:Glam – > BandCategory:categoryName:Rock 例如,我将如何使用NSPredicatesearch所有与乐队类别相匹配的乐队?

select标签时popup到根视图

我一直在遇到一些我认为可能很容易的麻烦。 我有一个表在我的根视图控制器,当select一个行我推新视图,从那里我去另一个选项卡。 我的问题是如何确保一旦用户点击第一个标签导航控制器将popup到根?

将UITextField文本更改为(*)星号字符

我怎么能改变一个安全的UITextField文本(这只是一堆点),以(*)星号字符像下面的图像?

如何在xCode 4.2中添加Entitlement.plist

我正在使用Xcode 4.2。 在这个版本中,我看不到任何添加Entitlements.plist的方法。 那么我怎样才能在我的项目中添加该文件,因为我需要在iPhone上安装我的应用程序。

UITableView选中的单元格在滚动时不会保持选定状态

滚动表格时,表格视图单元格不能保持其“选定”状态。 这是相关的代码: @property (nonatomic, strong) NSIndexPath *selectedIndexPath; -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { self.selectedIndexPath = indexPath; //do other stuff } -(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { MyCustomCell_iPhone* cell = [tableView dequeueReusableCellWithIdentifier:@"MyCustomCell_iPhone"]; if (cell == nil) cell = [[[NSBundle mainBundle] loadNibNamed:@"MyCustomCell_iPhone" owner:self options:nil] objectAtIndex:0]; if ([indexPath compare: self.selectedIndexPath] == NSOrderedSame) { [cell setSelected:YES animated:NO]; } return […]

在Swift中从App启动App Store

我正在创build一个应用程序,我有一个横幅,促进我的其他应用程序。 这是我的代码: var barsButton : UIButton = UIButton(frame: CGRectMake((self.view.bounds.width / 2) – 51, self.view.bounds.height – 100, 102, 30)) barsButton.setImage(UIImage(named: "Bars Icon 2.png"), forState: .Normal) barsButton.addTarget(self, action: "openBarsLink", forControlEvents: UIControlEvents.TouchUpInside) func openBarsLink() { var barsLink : String = "itms-apps:https://itunes.apple.com/app/bars/id706081574?mt=8" UIApplication.sharedApplication().openURL(NSURL.URLWithString(barsLink)) } 但是,当用户按下button时,它只是把他们带到App Store,而不是我的应用程序的特定页面。 我究竟做错了什么?

在笔尖或代码中deviseiPhone界面?

我一直在思考这个问题一段时间了… 一方面,Interface Builder提供了一种非常简单的方法来devise接口并将元素与代码中的对象连接起来。 另一方面,在大型项目中,Interface Builder成为维护的麻烦。 任何build议将不胜感激。