uikit

What does it mean to call initWithFrame on a UIView class or subclass with CGRectZero?

无人久伴 提交于 2019-12-21 02:43:20
问题 I have seen code that calls initWithFrame of a UIView subclass (such as UILabel ) with CGRectZero and things seem to work fine. What does it mean to instantiate a UIView subclass with a 2D point (which seems to be what CGRectZero is)? 回答1: It just means that you're instantiating the view without an initial value for its frame. This is done, for instance, when you want to create an instance of the view object and do not need to place it into the view hierarchy right away. Deciding upon and

How to download files from internet and save in 'Documents' on iPhone?

早过忘川 提交于 2019-12-21 02:26:12
问题 I have a folder on my remote server that has a few .png files in it. I want to download these from within my app and store them in the apps 'Documents' folder. How can I do this? 回答1: The easy way is to use NSData's convenience methods initWithContentOfURL: and writeToFile:atomically: to get the data and write it out, respectively. Keep in mind this is synchronous and will block whatever thread you execute it on until the fetch and write are complete. For example: // Create and escape the URL

UILabel default kerning different from CATextLayer

吃可爱长大的小学妹 提交于 2019-12-20 18:43:05
问题 I have a UILabel with the string 'LA'. I also have a CATextLayer with the same characters in an NSAttributedString assigned to its string property. The kerning in the UILabel is noticeably different from the CATextLayer . Here's the code. - (void)viewDidLoad { [super viewDidLoad]; // // UILabel // UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 50, 280, 100)]; label1.text = @"LA"; label1.backgroundColor = [UIColor clearColor]; label1.font = [UIFont fontWithName:@"Futura" size

How to display the iPhone/iPad keyboard over a full screen OpenGL ES app

浪子不回头ぞ 提交于 2019-12-20 18:26:30
问题 I'm working on an app that at some point requires keyboard input. My app uses OpenGL ES for display, and I have my own graphics framework that can display a text field, and knows how to manage the cursor and render text. This code works great on other platforms that have a physical keyboard, like Windows and OS X. All I need to get the iOS version of my app working is to be able to bring the keyboard up and down programmatically, and also to get the key press events from the user into my view

Drawing colored text in UIView's -drawRect: method

人走茶凉 提交于 2019-12-20 17:42:26
问题 I am trying to draw colored text in my UIView subclass. Right now I am using the Single View app template (for testing). There are no modifications except the drawRect: method. The text is drawn but it is always black no matter what I set the color to. - (void)drawRect:(CGRect)rect { UIFont* font = [UIFont fontWithName:@"Arial" size:72]; UIColor* textColor = [UIColor redColor]; NSDictionary* stringAttrs = @{ UITextAttributeFont : font, UITextAttributeTextColor : textColor };

Drawing colored text in UIView's -drawRect: method

£可爱£侵袭症+ 提交于 2019-12-20 17:39:59
问题 I am trying to draw colored text in my UIView subclass. Right now I am using the Single View app template (for testing). There are no modifications except the drawRect: method. The text is drawn but it is always black no matter what I set the color to. - (void)drawRect:(CGRect)rect { UIFont* font = [UIFont fontWithName:@"Arial" size:72]; UIColor* textColor = [UIColor redColor]; NSDictionary* stringAttrs = @{ UITextAttributeFont : font, UITextAttributeTextColor : textColor };

Checkbox cell in a table view: User can't check it

江枫思渺然 提交于 2019-12-20 17:32:15
问题 I need help in using checkbox cell. I currently added the object to tableview. It looks ok until i tried building and running the program where I cannot check the checkbox. I am currently using a tableview which displays items runtime with a checkbox for each item so i can have multiple selections. I am new to xcode and I have been stuck for a week with this problem. i tried google but still no luck. Any snippets, answers, or explanations is very much appreciated. 回答1: First we need to edit

Strange animation on iOS 7 when using hidesBottomBarWhenPushed in app built targeting <= iOS 6

心不动则不痛 提交于 2019-12-20 16:26:08
问题 This problem comes when I build an app targeting iOS 5 or 6, but run it on iOS 7. If I have a controller in a navigationController that is a part of a tabBarController, and I do the following: controller.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:testController animated:YES]; A strange vertical positioning animation occurs. I would instead like the new controller (with the bottom bar hidden) to push or pop on the navigation controller pushing the tab bar out

Strange animation on iOS 7 when using hidesBottomBarWhenPushed in app built targeting <= iOS 6

好久不见. 提交于 2019-12-20 16:25:51
问题 This problem comes when I build an app targeting iOS 5 or 6, but run it on iOS 7. If I have a controller in a navigationController that is a part of a tabBarController, and I do the following: controller.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:testController animated:YES]; A strange vertical positioning animation occurs. I would instead like the new controller (with the bottom bar hidden) to push or pop on the navigation controller pushing the tab bar out

UIButton image and background image, which one to use for custom image?

☆樱花仙子☆ 提交于 2019-12-20 16:22:37
问题 I am customizing my UIButton and I can either set image or background image. They both work fine but how do I decide which one to use? Are these two methods for when people have image that are broken up into foreground and background so they can layer them? 回答1: The background image is scaled to fill the bounds of the UIButton, and is displayed behind the title. The foreground image is not scaled, and displayed next to the button title. So if you want to put a title on your button, use the