I'm using default UITableViewCell and just set icon, label, detailLabel but for some reason with specific text length my icon jumps to the left top corner.
The issue is resolved after switching tab to another one and back.
Here is how it looks:
How it should look like:
It's related to text size and word-wrapping somehow because when I add or remove at least symbol - it works fine.
P.S. I've tried to tableView.reloadData on viewDidLoad, viewWillAppear etc and it doesn't help unfortunately.
UITableViewCell is default, no custom xib / storyboard.
Any ideas what's going on here?
Thanks!
Use auto-layout. Add constraints to icon and labels just.
Got it solved finally.
I was adding left green line like that:
let cellHeight = self.estimatedHeight(todo: todo)
let goalColorView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: 3, height: cellHeight))
cell.contentView.addSubview(goalColorView)
goalColorView.backgroundColor = todo.area.uiColor()
and just changed it to
cell.addSubview(goalColorView)
and now it works perfect.
Not sure why.. looks like contentView is just little bit tricky.
Thanks for all your suggestions!
Related
I'm trying to place a table view inside of a basic view controller without any padding on the top and nothing I've tried has worked, no matter what I do there is a gap up top. I placed the following code in my viewDidLoad() for the view controller:
if #available(iOS 11, *) {
tableView.contentInsetAdjustmentBehavior = .never
} else {
self.automaticallyAdjustsScrollViewInsets = false
}
I've gone into storyboard and disabled those settings as well manually:
I do have custom cells I'm not sure if that matters, I do add insetting to the cells but even when I remove that code I have that gap.
Here's the code I customized for my cells:
override func layoutSubviews() {
super.layoutSubviews()
contentView.frame = UIEdgeInsetsInsetRect(contentView.frame, UIEdgeInsetsMake(cellSpacingHeight, 0, 0, 0))
}
I've spent a couple hours googling around and I can't figure it out. I'm using the latest swift and Xcode to build this. I even tried to print the values for the tableView's content inset and it came up as all 0s. Does anyone know why I still have the offset or inset up top in my table view?
Wow okay so I finally figured it out, I had set the table view style to Grouped at some point instead of Plain. Once I made it plain, everything worked, I hope this might help someone else in this position!
I have a VC that has a UITableView all over the screen, except the first 66px from the top. There, I have a custom UIView I call "Toolbar" which contains a title and a button.
It looks like this:
I'm trying to add a shadow to the "Toolbar" that will be visible on top of the UITableView. I'm adding it like this:
For some reason, I don't see any shadow when I run the app.
What am I doing wrong? Does anybody know?
Thank you!
Shadow needs some spaces to be shown, you have to add some vertical spaces between your top view(toolbar) and the Table view.
for having a result like the following:
you need to add some space:
ans I also use the following code for adding the shadow:
toolbar.layer.shadowColor = UIColor.black.cgColor
toolbar.layer.shadowOpacity = 1
toolbar.layer.shadowOffset = CGSize.zero
toolbar.layer.shadowRadius = 10
toolbar.layer.masksToBounds = false
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).
I'm looking to have my textView in Xcode to start at the top because it is currently starting a little under the top.
//This is the code I'm using currently to try and have it start at the top
self.productDescription .scrollRangeToVisible(NSMakeRange(0, 0))
However this is not working. Anyone have any ideas what the problem could be?
The UITextView element has contentInsets by default. You can try changing the values of the textView.contentInset like so:
textView.contentInset = UIEdgeInsetsMake(-4,-8,0,0);
I am using storyboard and custom cells. In one of my labels I drugged on custom cell I need to print date. If date is arabic one, then I need to make label wider and print both dates -> arabic and christian.
My problem is that I am trying to access my label and change size:
if(str.length==ARABIC_DATE)
{
cell.lblYears.layer.frame = CGRectMake(0.0, 0.0, 50.0, 10.0);
cell.lblYears.backgroundColor=[UIColor blackColor];
cell.lblYears.text=str;
}
else
{
cell.lblYears.text=str;
}
The result is an additional label in wrong place (0.0, 0.0..). How to make that code will not produce an additional label, but will change the existing.
Thanx in advance.
You are not creating a second label in this code. You are placing an existing label in the (0,0) coordinate and setting 50 to the width and 10 to the height.
I don't know what your problem is exactly, but there is nothing wrong in that piece of code.