uikit

drawRect not being called in my subclass of UIImageView

巧了我就是萌 提交于 2019-12-17 09:08:14
问题 I have subclassed UIImageView and tried to override drawRect so I could draw on top of the image using Quartz 2D. I know this is a dumb newbie question, but I'm not seeing what I did wrong. Here's the interface: #import <UIKit/UIKit.h> @interface UIImageViewCustom : UIImageView { } - (void)drawRect:(CGRect)rect; @end And the implementation: #import "UIImageViewCustom.h" @implementation UIImageViewCustom - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { } return

scale Image in an UIButton to AspectFit?

无人久伴 提交于 2019-12-17 08:03:38
问题 I want to add an image to a UIButton, and also want to scale my image to fit with the UIButton (make image smaller). Please show me how to do it. This is what I have tried, but it does't work: Adding image to button and using setContentMode : [self.itemImageButton setImage:stretchImage forState:UIControlStateNormal]; [self.itemImageButton setContentMode:UIViewContentModeScaleAspectFit]; Making a "stretch image": UIImage *stretchImage = [updatedItem.thumbnail stretchableImageWithLeftCapWidth:0

How can I add CGPoint objects to an NSArray the easy way?

南笙酒味 提交于 2019-12-17 08:00:51
问题 I have about 50 CGPoint objects that describe something like a "path", and I want to add them to an NSArray. It's going to be a method that will just return the corresponding CGPoint for an given index. I don't want to create 50 variables like p1 = ...; p2 = ..., and so on. Is there an easy way that would let me to define those points "instantly" when initializing the NSArray with objects? 回答1: With UIKit Apple added support for CGPoint to NSValue , so you can do: NSArray *points = [NSArray

Offscreen UITableViewCells (for size calculations) not respecting size class?

孤街浪徒 提交于 2019-12-17 07:31:59
问题 I am using Auto Layout and size classes inside a UITableView with cells that self-size based on their content. For this I'm using the method where for each type of cell, you keep an offscreen instance of that cell around and use systemLayoutSizeFittingSize on that to determine the correct row height - this method is explained wonderfully in this StackOverflow post and elsewhere. This worked great until I started using size classes. Specifically I've defined different constants on the margin

How to figure out the font size of a UILabel when -adjustsFontSizeToFitWidth is set to YES?

老子叫甜甜 提交于 2019-12-17 07:24:21
问题 When myLabel.adjustsFontSizeToFitWidth = YES , UILabel will adjust the font size automatically in case the text is too long for the label. For example, if my label is just 100px wide, and my text is too long to fit with the current font size, it will shrink down the font size until the text fits into the label. I need to get the actual displayed font size from UILabel when the font size got shrunk down. For example, let's say my font size was actually 20, but UILabel had to shrink it down to

Show iPhone soft keyboard even though a hardware keyboard is connected

北城余情 提交于 2019-12-17 07:13:33
问题 My iPad app uses an external "device" that acts as a hardware keyboard. But, at some point in the settings, I need to input text and I can't use the "device" ("device" is not a keyboard). So, is there any way to force pop the soft keyboard even thought I have a hardware keyboard connected? 回答1: Yes. We've done this in a few of our apps for when the user has a Bluetooth scanner "keyboard" paired with the device. What you can do is make sure your textField has an inputAccessoryView and then

Are keys and values in an NSDictionary ordered?

筅森魡賤 提交于 2019-12-17 06:45:31
问题 I mean: Is the order of keys and values in an NSDictionary always the same like how they were specified when initializing the NSDictionary? Or should I better maintain a seperate NSArray if I really need to know the order of keys? 回答1: No, they are not ordered. As long as you don't add or remove any elements from the dictionary, they will remain in the same order, but as soon as you add or remove an element, the new order will be completely different. If you need the keys/values to be ordered

Detecting sheet was dismissed on iOS 13

痞子三分冷 提交于 2019-12-17 06:43:13
问题 Before iOS 13, presented view controllers used to cover the entire screen. And, when dismissed, the parent view controller viewDidAppear function were executed. Now iOS 13 will present view controllers as a sheet as default, which means the card will partially cover the underlying view controller, which means that viewDidAppear will not be called, because the parent view controller has never actually disappeared. Is there a way to detect that the presented view controller sheet was dismissed

UIPageViewController returns no Gesture Recognizers in iOS 6

偶尔善良 提交于 2019-12-17 06:34:12
问题 I am trying to disable the pan gesture recognizer for a UIPageViewController. On iOS 5 I can loop through them and disable them. for (UIGestureRecognizer* recognizer in self.pageViewController.gestureRecognizers) { if ([recognizer isKindOfClass:[UIPanGestureRecognizer class]]) { recognizer.enabled = NO; } } On iOS 6 using UIPageViewControllerTransitionStyleScroll there are no gesture recognizers returned by the Page View Controller. Clarification This can be boiled down to: self

iPhone development: How to create colored or translucent background for UIActionSheet?

╄→尐↘猪︶ㄣ 提交于 2019-12-17 06:30:31
问题 When you try deleting a note in iPhone's Notes application, an UIActionSheet pops up. The sheet is translucent (but not black translucent). How is that achieved? Is it possible to make the background of UIActionSheet a certain color? 回答1: I usually implement the following delegate method: - (void)willPresentActionSheet:(UIActionSheet *)actionSheet Just to make a sample. In this case I use a stretched png as a background: - (void)willPresentActionSheet:(UIActionSheet *)actionSheet { UIImage