cocoa-touch

How can I programmatically dismiss the autocorrect popover in a UITextView?

南笙酒味 提交于 2019-12-30 05:32:07
问题 I'm doing some custom auto-complete stuff on my own with insertText: , but if there's an autocorrect suggestion visible the view gets into a weird state. If I use [textView unmarkText] , it dismisses the autocorrect popup thingy -- but it accepts the autocorrection (which is bad). Is there some way to programmatically reject the autocorrect suggestion? My current "solution" works, but it's gross and hacky and I have no reason to assume it will continue to work in the future. Is there a better

How do I implement a soft eraser stroke in a CGBitmapContext

我怕爱的太早我们不能终老 提交于 2019-12-30 05:28:09
问题 I am trying to erase an image with my touch in iOS. By setting the blend mode to kCGBlendModeClear I am able to do this - but only with hard edges. I could draw my stroke with varying line widths and alphas, but it appears that CGContextSetAlpha does not have an effect with kCGBlendModeClear. How do I go about this? 回答1: I would use a transparency layer compositing with kCGBlendModeDestinationOut ( Da * (1 - Sa), Dc * (1 - Sa) .) Something like this: CGPathRef pathToErase = ...; // The path

How to create a macro with multiple lines of code?

浪子不回头ぞ 提交于 2019-12-30 05:28:08
问题 I want to make a macro which will inject some code, like: if (foo) { [Bar fooBar]; } and then, where ever I need that, I put FOOBAR in the code. Not sure, but at compile time then the compiler replaces this with the actual code like in the example above. Maybe there's something different than a macro I could use for this? 回答1: Use \ to escape each line-break you want to be part of the macro. However, be aware that using macros like this can hide structure if you aren't careful. Taking your

Presenting an image cropping interface

血红的双手。 提交于 2019-12-30 05:11:13
问题 I'm trying to engineer a UI for cropping images in iphone OS and suspect I'm going about things the hard way. My goal is pretty much what the Tapbots duo have done with Pastebot. In that app, they dim the source image but provide a movable and resizable cropping view and the image you're cropping is in a zoomable scrollview; when you resize or move the underlying image, the cropping view adjusts appropriately. I mocked up a composite image which will give a sense of the design I'm after,

How to split items in a string separated by “,”

爷,独闯天下 提交于 2019-12-30 04:58:15
问题 In my App, data comes in String like this "Hi,Hello,Bye" I want to separate data by "," How can I do that? 回答1: use componentsSeparatedByString: NSString *str = @"Hi,Hello,Bye"; NSArray *arr = [str componentsSeparatedByString:@","]; NSString *strHi = [arr objectAtIndex:0]; NSString *strHello = [arr objectAtIndex:1]; NSString *strBye = [arr objectAtIndex:2]; 回答2: NSString *str = @"Hi,Hello,Bye"; NSArray *aArray = [str componentsSeparatedByString:@","]; For more info, look at this post. 回答3:

What is the fastest way to draw single pixels directly to the screen in an iPhone application?

╄→尐↘猪︶ㄣ 提交于 2019-12-30 04:58:09
问题 I am looking the fastest way to draw thousands of individually calculated pixels directly to the screen in an iPhone application that preforms extremely well. 回答1: Most probably using OpenGL, something like: glBegin(GL_POINTS); glColor3f(...); glVertex3f(...); ... glEnd(); Even faster would probably be to use vertex arrays for specifying the points. 回答2: Why don't you use OpenGL views? 回答3: In all graphics frameworks I've ever used, the way you'd do this is to write your pixels into a block

how to clear all the rows of uitableview

被刻印的时光 ゝ 提交于 2019-12-30 04:51:06
问题 I added a button on the uinavigationbar I want to use it to clear all the rows of uitablview How can I do that? 回答1: A bit late... but try this: Where you want to clear the table: // clear table clearTable = YES; [table reloadData]; clearTable = NO; This function should look like: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if(clearTable) return 0; (...) } 回答2: There should be a UITableView delegate method that populates the UITableView control:

Removing shadows from UIWebView

ε祈祈猫儿з 提交于 2019-12-30 04:36:51
问题 I use a web view to display small pdf files. In the interest of aesthetics, I'd like to remove the grey border around the PDF. Is there any way around it? I've looked at various resources none of which seem to work or the solution no longer works in iOS5. Also, is there any way of stopping the scroll if there's only one page? Thanks. 回答1: The shadows are actually UIImageView subviews of the UIScrollView (or the equivalent in iOS5 UIWebView). So in iOS4: for (UIView* subView in [webView

Generate CSV sample iphone app/code

余生长醉 提交于 2019-12-30 03:41:07
问题 Does anyone have a sample app or some sample code to generate a CSV file on iOS? 回答1: My CHCSVParser will both read and write CSV files on OS X and iOS. It comes with some examples of how to use it. 回答2: Here is a simple code to generate CSV file : NSArray *csvArray = [myTextView.text componentsSeparatedByString:@"\n"]; NSString *csvString = [csvArray componentsJoinedByString:@","]; NSLog(@"csvString:%@",csvString); // Create .csv file and save in Documents Directory. //create instance of

Obtaining a server IP address from hostname

心已入冬 提交于 2019-12-30 03:31:24
问题 When performing an NSURLRequest to a hostname, is it possible to obtain the IP address of the server that the response came from? The NSURL method: - (NSString *)host; simply returns the hostname, and I see no way of obtaining the IP address from any of the other NSURL methods. Perhaps there is a way of performing a host lookup before inititing the NSURLRequest ? 回答1: You can use the system call gethostbyname() to resolve a hostname then use the returning structure to get the ip address. Have