Given a view, how do I get its viewController?

From the UIResponder documentation for nextResponder: The UIResponder class does not store or set the next responder automatically, instead returning nil by default. Subclasses must override this method to set the next responder. UIView implements this method by returning the UIViewController object that manages it (if it has one) or its superview (if it doesn’t); … Read more

How to add a border just on the top side of a UIView

I consider subclassing UIView and overriding drawRect overkill here. Why not add an extension on UIView and add border subviews? @discardableResult func addBorders(edges: UIRectEdge, color: UIColor, inset: CGFloat = 0.0, thickness: CGFloat = 1.0) -> [UIView] { var borders = [UIView]() @discardableResult func addBorder(formats: String…) -> UIView { let border = UIView(frame: .zero) border.backgroundColor = … Read more

Dashed line border around UIView

Another method if you like sublayers. In your custom view’s init, put this (_border is an ivar): _border = [CAShapeLayer layer]; _border.strokeColor = [UIColor colorWithRed:67/255.0f green:37/255.0f blue:83/255.0f alpha:1].CGColor; _border.fillColor = nil; _border.lineDashPattern = @[@4, @2]; [self.layer addSublayer:_border]; And in your layoutsubviews, put this: _border.path = [UIBezierPath bezierPathWithRect:self.bounds].CGPath; _border.frame = self.bounds;

Load a UIView from nib in Swift

My contribution: extension UIView { class func fromNib<T: UIView>() -> T { return Bundle(for: T.self).loadNibNamed(String(describing: T.self), owner: nil, options: nil)![0] as! T } } Then call it like this: let myCustomView: CustomView = UIView.fromNib() ..or even: let myCustomView: CustomView = .fromNib()

UIView’s frame, bounds, center, origin, when to use what?

Marco’s answer above is correct, but just to expand on the question of “under what context”… frame – this is the property you most often use for normal iPhone applications. most controls will be laid out relative to the “containing” control so the frame.origin will directly correspond to where the control needs to display, and … Read more

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

Is it possible to set UIView border properties from interface builder?

Actually you can set some properties of a view’s layer through interface builder. I know that I can set a layer’s borderWidth and cornerRadius through xcode. borderColor doesn’t work, probably because the layer wants a CGColor instead of a UIColor. You might have to use Strings instead of numbers, but it works! layer.cornerRadius layer.borderWidth layer.borderColor … Read more

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