I have a UIView on my UIViewController. I set width and height using Editor -> Pin -> Width/Height. Also i created IBOutlet of these constraints to change widht and height programatically. I worte code
in .h file
#property (strong, nonatomic) IBOutlet NSLayoutConstraint *viewWidth;
#property (strong, nonatomic) IBOutlet NSLayoutConstraint *viewHeight;
in .m file
self.viewWidth.constant = 480;
self.viewHeight.constant = 644;
but still its not changing the width and height of view. Am i missing something?
Thanks in advance.
After updating the constants, you need to invoke -layoutIfNeeded or -setNeedsUpdateConstraints.
Here a solution to update constants of constraints programmatically without IBOutlet.
Hide autolayout UIView : How to get existing NSLayoutConstraint to update this one
Related
I am testing custom keyboard extension in iPhone X. I just created a new project with Keyboard extension. As you see in 2 photos , custom keyboard's height is like only a half of system keyboard's height. I don't know why. Is there any way to get actual keyboard height like system keyboard height?
Custom Keyboard
iOS System Keyboard
Here you go. Write this piece of code in viewDidAppear.
CGFloat _expandedHeight = 500; //The height you want
NSLayoutConstraint *_heightConstraint =
[NSLayoutConstraint constraintWithItem: self.view
attribute: NSLayoutAttributeHeight
relatedBy: NSLayoutRelationEqual
toItem: nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier: 0.0
constant: _expandedHeight];
[self.view addConstraint: _heightConstraint];
In iOS 8.0, you can adjust a custom keyboard’s height any time after its primary view initially draws on screen.
Is there way how to scale/resize entire canvas made in fabric.js ? I have <canvas className="canvas" ref="canvas" width="895" height="560"></canvas> then const canvas = new fabric.Canvas(this.refs.canvas),can i change width and height of canvas element and all objects inside ??
This question has been answered many times.
The best answer on my opinion provided by one of fabricjs contributors Andrea Bogazzi here: https://stackoverflow.com/a/35019311/3710047
Basically, you can use fabricjs canvas methods:
canvas.setZoom(val);
canvas.setWidth(originalWidth * canvas.getZoom());
canvas.setHeight(originalHeight * canvas.getZoom());
I'm rendering multiple layers to get one final image. One of the images contains a face, and another one contains a background with a transparent gradient around the face so that the real background is hidden. In iOS6 it works perfectly but it is creating a weird effect with the transparent gradient in iOS7.
The code:
CGRect rect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[faceImageView.layer renderInContext:context];
[fakeBackgroundImageView.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
The results in iOS6 and iOS7:
Ok, the solution was changing this line:
UIGraphicsBeginImageContext(rect.size);
for this one:
UIGraphicsBeginImageContextWithOptions(rect.size, TRUE, [[UIScreen mainScreen] scale]);
Now it also works in iOS7
# I have a UITableView with custom UITableViewCells. My views are autorotated on orientation as I have implemented the ios6 orientation methods.
# I am not using xib file and drawing all the contents programmatically (imageView,label).
When I rotate my device the tableView and Cells are rotated but cell subviews are not proper in terms of size and position.
# So how to resize the current cells being drawn on the TableView. As the cells are drawn asynchronously and not all at once, how to apply resizing ?
# Do I need to apply AutoResizingMasks or NSLayoutConstraint ? My TabBar and NavigationBar are properly resized but cells are not.
***Plz note: I have not added any block of code, bcoz I simply dnt understand how to proceed as for already drawn cells and those being drawn dynamically after objectForRowAtIndexPath.
I have found the answer. As for orientation in ios6, there are many links for implementing new methods.
Initially my views were not supporting rotation till I found that my tabBarController was a RootViewController for the app so I added (BOOL)shouldAutorotate
{return YES;
} in my subclassed TabBarController class
and in my info.plist added key value pairs for supported interface orientations, this values will be global to the application unless you specify exceptions in current UIViewController via - (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
For implementing rotation in UITableView, I called reloadData(); via using - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self.tableView reloadData];
}
Its not necessary to write a custom UITableViewCell Class, as you can redraw cells in – tableView:cellForRowAtIndexPath: method. As I already had a custom UITableViewCell Class I draw new cells in layoutSubviews(); by getting [[UIApplication sharedApplication] statusBarOrientation] method. If you have any custom UIViews inside the cell you need to redraw the rect to support the landscape mode. Basically I am also supporting ios5 so I am not using AutoLayout via XIB. You can also use autoresizing masks to each subviews as per your layout frames.
reloadData(); is not expensive to memory as you don't call for all the cells # the same time and only the visible cells in the UITableView are redrawn and cells are reused as before.
I have a view containing a containerView (gray), which contains a UILabel (blue).
I have layout constraints such that the containerView is always 8 pixels larger than the label on each side, and the containerView's borders left/top/right are fixed. The container view stretches appropriately when the device orientation changes.
The label's numberOfLines property is set to 0. I am setting the label's text in code. The label's height grows to accommodate the text, as expected.
Here's the problem: When I rotate the device to landscape, the label's width grows to fit into the screen's available width, and the text will fit on 2 lines. But the UILabel does not shrink its height to fit snugly around the text. Notice the extra space above and below the text in the label.
So how can I make the label's height shrink with the device is rotated to fit snugly around the text?
I have tried calling [myLabel sizeToFit] in the viewWill/DidLayoutSubviews method, but this had no visible effect.
Check if the label has a constraint that specifies a fixed height: NSLog(#"%#", label.constraints);
Step 1: Subclass UILabel.
Step 2: Set the label's custom class to your label subclass.
Step 3: Override -layoutSubviews in your custom class.
Step 4: In the overridden method, call [self sizeToFit];
This worked for me.