Tutorial by Examples

Objective-C CGRect myFrame = CGRectMake(0, 0, 320, 35) UIView *view = [[UIView alloc] initWithFrame:myFrame]; //Alternative way of defining the frame UIView *view = [[UIView alloc] init]; CGRect myFrame = view.frame; myFrame.size.width = 320; myFrame.size.height = 35; myFrame.origin.x = 0;...
To make a rounded UIView, specify a cornerRadius for the view's layer. This also applies any class which inherits from UIView, such as UIImageView. Programmatically Swift Code someImageView.layoutIfNeeded() someImageView.clipsToBounds = true someImageView.layer.cornerRadius = 10 Objective-C...
You can take a snapshot from a UIView like this: Swift let snapshot = view.snapshotView(afterScreenUpdates: true) Objective-C UIView *snapshot = [view snapshotViewAfterScreenUpdates: YES];
One (or two) of the coolest new features in recent Xcode releases are the IBInspectable properties and IBDesignable UIViews. These have nothing to do with the functionality of your application but instead impact the developer experience in Xcode. The goal is to be able to visually inspect custom v...
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) view.backgroundColor = UIColor.orange self.view.addSubview(view) UIView.animate(withDuration: 0.75, delay: 0.5, options: .curveEaseIn, animations: { //This will cause view to go from (0,0) to // (self.view.frame.origi...
If we want to get the x-cordinate of origin of the view, then we need to write like: view.frame.origin.x For width, we need to write: view.frame.size.width But if we add a simple extension to an UIView, we can get all the attributes very simply, like: view.x view.y view.width view.height...
Suppose you have a parentView into which you want to insert a new subView programmatically (eg. when you want to insert an UIImageView into a UIViewController's view), than you can do it as below. Objective-C [parentView addSubview:subView]; Swift parentView.addSubview(subView) You can also...
UIView *view = [[UIView alloc] init]; [self.view addSubview:view]; //Use the function if you want to use height as constraint [self addView:view onParentView:self.view withHeight:200.f]; //Use this function if you want to add view with respect to parent and should resize with it [self a...
When creating a UIView subclass, intrinsic content size helps to avoid setting hardcoded height and width constraints a basic glimpse into how a class can utilize this class ImageView: UIView { var image: UIImage { didSet { invalidateIntrinsicContentSize() } ...
extension UIView { func shake() { let animation = CAKeyframeAnimation(keyPath: "transform.translation.x") animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear) animation.duration = 0.6 animation.values = [-10.0, 10.0, ...

Page 1 of 1