Problems resizing UICollectionView - ios

I have two UICollectionViews on the screen. After onClick event I want to resize one of them.
My problem is that the UICollectionVies doesn't change its size, it is moving to other screen position.
The original frame size is:
(0, 0, 1024, 588)
I have tried with this:
collectionView.Frame = new CGRect(0, 0 , 1024 , 768);
and this:
this.viewer.Bounds= new CGRect(0, 0 , 1024 , 768);
But nothing works.
I also followed this link Resize UICollectionView Height but doesn't works for me.
Thanks in advance.

Related

Increasing height of UIView.frame programmatically works till iPhone 8 plus but doesn't works beyond model iphone x

I am increasing the height for UIView programmatically in runtime on click of button, it works fine on iPhone 6,7,8 and plus models but doesn't works on iPhone X and beyond models. i have initially set constraints programmatically as i views are autoLayout based. I also tried to set constraints at runtime which didn't helped too.
//Tried this and working till iPhone 8+
self.view.frame.size.height += CGFloat(280)
//or
self.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width,
height: self.view.frame.height + 20.0)
//Tried setting height constraint
self.view.autoSetDimension(.height, toSize: 270)
Debug view hierarchy and look for conflicting constraints that might interfere with your height constraint. Also make sure you set translatesAutoresizingMaskIntoConstraints to false if you set constraints in code.
Also: if you set your constraint like this in code (apparently you are using PureLayout), that method returns the reference to that height constraint. So if you want to modify it, you need to update the constant value of your constraint, instead of setting a new one.
For any further help you certainly need to share more information.

Two identical CGSize's and one appears smaller

I have an ImageView and I have a CustomView that I want to appear the same size on screen.
public override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
progress.frame.size = circle.frame.size
print("Progress frame size w: \(progress.frame.size.width) h: \(progress.frame.size.height)
print("Circle frame size w: \(circle.frame.size.width) h: \(circle.frame.size.height)
//Progress frame size w: 300 h: 300
//Circle frame size w: 300 h: 300
and yet they appear with different size on the Simulator:
I tried setting the bounds instead of frame. I also tried calculating the difference from the view to the circle and setting the progress frame according to that:
let widthDifference = UIScreen.main.bounds.width - circle.frame.size.width
let progressWidth = UIScreen.main.bounds.width - widthDifference
...
but no success.
I don't know what's happening, I am really new to iOS development and many things are weird to me.
The size of the progress bar was fine when the scene was wrapped in a NavigationController. When I removed the NavigationController the dimensions were totally screwed.
FYI: Circle is an image view. Progress is a third-party circular progress bar
Thank you for your time!
Your progress bar is indeed the same size of your circle but that doesn't mean that the bar will take the full size of 300px for diameter.
If you are curious, take a look at this line from the library, and also this line to see how the radius is created.
You can also try to print out the value of arcRadius and it must be smaller than 150px.

iOS Swift Setting View Frame Position Programmatically

I having two sub views inside scrollview. I need to position that both subviews programmatically. I did it correctly by writing code inside DispatchQueue.main.async. Here is the code:
DispatchQueue.main.async {
self.SelectClientDetailView.frame = CGRect(x: 0, y: 637, width: self.SelectClientDetailView.frame.size.width, height: self.SelectClientDetailView.frame.size.height)
self.SelectClientDetailView2.frame = CGRect(x: 0, y: 837, width: self.SelectClientDetailView2.frame.size.width, height: self.SelectClientDetailView2.frame.size.height)
}
Its working good but when I scrolling my scrollview this both views set back to old positions. How to fix it. Its Default y position will be SelectClientDetailView:400 and SelectClientDetailView2: 600
If you are using Auto Layout then setting frame will cause some weird effects. Auto Layout and Frames doesn't go together. You'll need to rearrange the constrains, not the frames. While using Auto Layout changing the frames will cause some weird effects and will eventually revert back to the constraints you've created in the original UIView.
Some solutions:
If you want to use Autolayout approach then, You need to create an outlet to each constrain just like you would to a view and change its constant when needed.
disable Auto Layout in that specific xib and start playing with frames.
If you only want to change the frame Y position, try this instead:
self.SelectClientDetailView.frame.origin.y = 637
self.SelectClientDetailView.frame.origin.y = 837
As already mentioned, you might need to check your view hierarchy to be sure you are actually adding them to the UIScrollView (and not elsewhere).

Swift: programmatically align labels for different IOS screen sizes

I'm new to Swift and ios development. I have 6 labels and a horizontal SKScene in my App. I would like to align those 6 labels beautifully and automatically. Now I have fixed the positions and the alignment always looks awful on some screen size while good on other.
I have not used storyboards or other graphical editors for building the ui but everything is done in code. Therefore I'm looking for a programmatic solution (code examples) for handling the alignment.
If you want to place them in the middle of the screen horizontally, but give them different y positions, you could just do something like this for each label:
label.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMaxY(self.frame) * 0.80)
To place them at different y positions, just multiply by the maxY by a different decimal number. This way, all of the labels are aligned along the x-axis and appear at different y-positions, like a column and they will appear this way on every screen size because they are positioned relative to the screen size and not in a fixed position.
You can align the labels (lets say at the center of the screen) like this.
var label1 = UILabel(CGRectMake: 0, 0, 200, 40)
label1.center = CGPointMake(UIScreen.mainScreen().bounds.size.width/2, 30)
var label2 = UILabel(CGRectMake: 0, 0, 200, 40)
label2.center = CGPointMake(UIScreen.mainScreen().bounds.size.width/2, label1.center.y + 30)
and so on. Just reference the main screen bounds and not static points for alignment, so that they are centered in any screen size.
What I ended up doing was to create an empty SKSprite to which I included the SKLabels. Now I can control by the pixed the distances between labels but align the top-level sprite in the middle of the screen despite screen size.

iPad - AG.Calendar doesn't go full width

Version used: 1.2.3
I added the modules to my tiapp.xml:
ag.calendar
here's a link to what it looks like: https://dl.dropbox.com/u/101794062/iOS%20Simulator%20Screen%20shot%20Oct%2031%2C%202012%2010.35.51%20PM.png
I made sure that there are no actual static width's set. The weird thing is that the calendar is starting to go the full width, but not quite. The header part and the footer part of the calendar just aren't going the full width.
Link to the module I used: https://github.com/Appgutta/AGCalendar
In the KalViewController.m replace line 196 with the following:
CGRect rect = CGRectMake(0, 0, windowsRect.size.width, windowsRect.size.height);
//CGRect rect = CGRectMake(0, 0, MIN(popoverRect.size.width, windowsRect.size.width), MIN(popoverRect.size.height, windowsRect.size.height));

Resources