cocoa-touch

How to calculate the height of the text rectangle from an NSString?

旧城冷巷雨未停 提交于 2020-01-01 03:13:07
问题 I know there is this one: sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode: But since the CGSize always has the same height and doesn't adjust to any shrinked text or whatsoever, the CGSize is not telling how heigh the text is. Example: Make a UILabel with 320 x 55 points and put a loooooooooooooong text in there. Let the label shrink the text down. Surprise: CGSize.height remains the same height even if the text is so tiny that you need a microscope. Ok so after banging my head

Adjust the brightness of the screen through code

喜夏-厌秋 提交于 2020-01-01 03:02:07
问题 I am developing an iPhone application and I need to adjust the brightness of the screen through my application, in the same way as we do through the Settings app. I have searched but have not found a solution. 回答1: You can use: [[UIScreen mainScreen] setBrightness:1.0]; But only on iOS 5. Not supported on earlier iOS versions. 回答2: If you require compatibility with older iOS versions, try a black overlay on top of your application's main window with partial alpha. I used it in an iPad app -

swipe to delete when already in edit mode

浪尽此生 提交于 2020-01-01 02:51:47
问题 I have an iphone app using a uitableview where I'd like the "reorder" controls to always be displayed, and have the user swipe to delete rows. The approach I'm currently taking is to put the tableview in edit mode and allow selection in edit mode self.tableView.editing = YES; self.tableView.allowsSelectionDuringEditing = YES; I then hide the red delete circles using - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

How to flip coordinates when drawing in context?

人走茶凉 提交于 2020-01-01 02:41:06
问题 I create a context from an UIImage, and then I draw into it with CGContextDrawImage(bitmapContext, CGRectMake(0, 0, originalImage.size.width, originalImage.size.height), oImageRef); the image appears upside-down due to the flipped coordinate system in quartz. How can I fix that? 回答1: You should be able to transform the context using something similar to the following: CGContextSaveGState(bitmapContext); CGContextTranslateCTM(bitmapContext, 0.0f, originalImage.size.height); CGContextScaleCTM

“Whole word” search in a NSString through NSPredicate

99封情书 提交于 2020-01-01 01:13:16
问题 I would like to search if in the attribute description (an NSString instance) there is a given word. I tried with this predicate: [NSPredicate predicateWithFormat:@"description CONTAINS[cd] %@", theWord]; It works, but it finds also sub-words . For example, given theWord : Car it will mach also this description : A Christmas Carol Instead, I would like that my predicate will match only a , or christmas , or carol . (I'm using Core Data and NSFetchRequest.) 回答1: Something like this? NSString

iPhone API for Accessing Amazon S3 REST API

久未见 提交于 2020-01-01 00:54:06
问题 Does anyone have any suggestions for GETing from or POSTing to Amazon S3 services using their REST API via the iPhone. It does not look like it is possible but I may be reading the docs wrong. Thank you in advance for your help! L. 回答1: In a general case I'd recommend to use ASIHttpRequest, it has a lot of built-in functionality (REST compatible too) and a lot of things, making life easier than with NSURLConnection. It also has S3 support out of box. 回答2: You should be able to use the

NSFetchedResultsController returning objects with null indexPaths

跟風遠走 提交于 2020-01-01 00:48:10
问题 Details are in the comments. The following code: // Perform the fetch... NSError *error = nil; if (![[self fetchedResultsController] performFetch:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } // Confirm that objects were fetched by counting them... NSLog(@"Number of Objects = %i", [[fetchedResultsController fetchedObjects] count]); // Confirm that sections exist by counting them... NSLog(@"Numbers of Sections = %i", [[fetchedResultsController sections]

Show a UIPopoverController from a detail disclosure button in a UITableViewCell

纵饮孤独 提交于 2020-01-01 00:45:38
问题 I am creating an application for the iPad, and I want to show an UIPopoverController with an arrow pointing to the detail disclosure button for the row it belongs to. I want to do this in the tableView:accessoryButtonTappedForRowWithIndexPath: method. Currently I have this, with a dummy CGRect : - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { // Dismiss in the case it shows itself somewhere else [addFeedPopup

Show a UIPopoverController from a detail disclosure button in a UITableViewCell

血红的双手。 提交于 2020-01-01 00:45:25
问题 I am creating an application for the iPad, and I want to show an UIPopoverController with an arrow pointing to the detail disclosure button for the row it belongs to. I want to do this in the tableView:accessoryButtonTappedForRowWithIndexPath: method. Currently I have this, with a dummy CGRect : - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { // Dismiss in the case it shows itself somewhere else [addFeedPopup

New error in iOS 5: WebKit discarded an uncaught exception

…衆ロ難τιáo~ 提交于 2019-12-31 22:40:11
问题 I am trying to load a UIWebView with the Facebook OAuth authorization URL and I am using the following code. When my UIWebView loads with Facebook login page, I enter my credentials, then press the "Log in" button. When I hit the button I am getting the following error: WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener:delegate: Application tried to present modally an active controller . This same code works fine with iOS 4.3