How do I change the color of the text in a UIPickerView under iOS 7?

There is a function in the delegate method that is more elegant: Objective-C: – (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component { NSString *title = @”sample title”; NSAttributedString *attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}]; return attString; } If you want to change the selection bar colors as well, I found that I had to add 2 … Read more

How do I create a custom iOS view class and instantiate multiple copies of it (in IB)?

Swift example Updated for Xcode 10 and Swift 4 (and reportedly still works for Xcode 12.4/Swift 5) Here is a basic walk through. I originally learned a lot of this from watching this Youtube video series. Later I updated my answer based on this article. Add custom view files The following two files will form … Read more

What is the most robust way to force a UIView to redraw?

The guaranteed, rock solid way to force a UIView to re-render is [myView setNeedsDisplay]. If you’re having trouble with that, you’re likely running into one of these issues: You’re calling it before you actually have the data, or your -drawRect: is over-caching something. You’re expecting the view to draw at the moment you call this … Read more

Rounded UIView using CALayers – only some corners – How?

Starting in iOS 3.2, you can use the functionality of UIBezierPaths to create an out-of-the-box rounded rect (where only corners you specify are rounded). You can then use this as the path of a CAShapeLayer, and use this as a mask for your view’s layer: // Create the path (with only the top-left corner rounded) … Read more

How does clipsToBounds work?

If my superview is a box measuring 10 units on each side, and my subview is 20 units wide, with clipsToBounds set to YES, I’ll only see the part of the subview that fits within the bounds of the superview. Otherwise, if clipsToBounds is set to NO, I’ll see the entire subview, even the parts … 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

Understand convertRect:toView:, convertRect:FromView:, convertPoint:toView: and convertPoint:fromView: methods

Each view has its own coordinate system – with an origin at 0,0 and a width and height. This is described in the bounds rectangle of the view. The frame of the view, however, will have its origin at the point within the bounds rectangle of its superview. The outermost view of your view hierarchy … Read more

Completion block for popViewController

I know an answer has been accepted over two years ago, however this answer is incomplete. There is no way to do what you’re wanting out-of-the-box This is technically correct because the UINavigationController API doesn’t offer any options for this. However by using the CoreAnimation framework it’s possible to add a completion block to the … Read more

Changing my CALayer’s anchorPoint moves the view

I had the same problem. Brad Larson’s solution worked great even when the view is rotated. Here is his solution translated into code. -(void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view { CGPoint newPoint = CGPointMake(view.bounds.size.width * anchorPoint.x, view.bounds.size.height * anchorPoint.y); CGPoint oldPoint = CGPointMake(view.bounds.size.width * view.layer.anchorPoint.x, view.bounds.size.height * view.layer.anchorPoint.y); newPoint = CGPointApplyAffineTransform(newPoint, view.transform); oldPoint = CGPointApplyAffineTransform(oldPoint, view.transform); CGPoint position … Read more

How Do I Take a Screen Shot of a UIView?

iOS 7 has a new method that allows you to draw a view hierarchy into the current graphics context. This can be used to get an UIImage very fast. I implemented a category method on UIView to get the view as an UIImage: – (UIImage *)pb_takeSnapshot { UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [UIScreen mainScreen].scale); [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES]; // … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)