How to Convert UIView to PDF within iOS?

Note that the following method creates just a bitmap of the view; it does not create actual typography. (void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename { // Creates a mutable data object for updating with binary data, like a byte array NSMutableData *pdfData = [NSMutableData data]; // Points the pdf converter to the mutable data object and to the UIView … Read more

NSAttributedString background color and rounded corners

I managed to achieve the above effect, so thought I’d post an answer for the same. If anyone has any suggestions about making this more effective, please feel free to contribute. I’ll be sure to mark your answer as the correct one. 🙂 For doing this, you’ll need to add a “custom attribute” to NSAttributedString. … Read more

Autoresizing masks programmatically vs Interface Builder / xib / nib

Yes, you have cited things correctly. Also, I agree that it feels a bit backwards, so for that reason I appreciate your post. You might like using a preprocessor Macro UIViewAutoresizingFlexibleMargins when making a UIView’s margin flexible in every direction. I put this in the precompiled header file so it gets included everywhere. #define UIViewAutoresizingFlexibleMargins … Read more

How to convert a UIView to an image

An extension on UIView should do the trick. extension UIView { // Using a function since `var image` might conflict with an existing variable // (like on `UIImageView`) func asImage() -> UIImage { let renderer = UIGraphicsImageRenderer(bounds: bounds) return renderer.image { rendererContext in layer.render(in: rendererContext.cgContext) } } } Apple discourages using UIGraphicsBeginImageContext starting iOS 10 … Read more

UIView Infinite 360 degree rotation animation?

Found a method (I modified it a bit) that worked perfectly for me: iphone UIImageView rotation #import <QuartzCore/QuartzCore.h> – (void) runSpinAnimationOnView:(UIView*)view duration:(CGFloat)duration rotations:(CGFloat)rotations repeat:(float)repeat { CABasicAnimation* rotationAnimation; rotationAnimation = [CABasicAnimation animationWithKeyPath:@”transform.rotation.z”]; rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ]; rotationAnimation.duration = duration; rotationAnimation.cumulative = YES; rotationAnimation.repeatCount = repeat … Read more

Giving UIView rounded corners

Try this #import <QuartzCore/QuartzCore.h> // not necessary for 10 years now 🙂 … view.layer.cornerRadius = 5; view.layer.masksToBounds = true; Note: If you are trying to apply rounded corners to a UIViewController‘s view, it should not be applied in the view controller’s constructor, but rather in -viewDidLoad, after view is actually instantiated.

Get to UIViewController from UIView?

Using the example posted by Brock, I modified it so that it is a category of UIView instead UIViewController and made it recursive so that any subview can (hopefully) find the parent UIViewController. @interface UIView (FindUIViewController) – (UIViewController *) firstAvailableUIViewController; @end @implementation UIView (FindUIViewController) – (UIViewController *) firstAvailableUIViewController { UIResponder *responder = [self nextResponder]; while … Read more