UIDropDown icon indicating copy to clipboard operation
UIDropDown copied to clipboard

Text alignment issue

Open AussieSam opened this issue 6 years ago • 0 comments

I believe that there is an issue which makes the text alignment dependent on the "View As" selection made it xCode. This means that it will not be possible to make the drop down appear correctly on both an iPhone and iPad at the same time.

To clarify, this is only an issue when you specify leading and trailing widths to say superview. If instead, you were to center the UIDropdown on the x axis and explicitly specify the width then you would have no issue, but you would have a small dropdown on an iPad

The below change appears to have fixed the issue, I have used screenSize.width rather than self.frame.width

    fileprivate func setup() {
    let screenSize: CGRect = UIScreen.main.bounds
    let screenWidth = screenSize.width
    let screenHeight = screenSize.height
    title = UILabel(frame: CGRect(x: 0,
                                  y: 0,
                                  width: (screenWidth-self.frame.height),
                                  height: self.frame.height))

    title.textAlignment = .center
     print("\(self.frame.width)")
    print("\(screenWidth)")
    self.addSubview(title)
   

There may be a way to specify the object width when the dropdown is set up. I tried but it didnt affect the actual size of self.frame.width inside the UIDropDown class

dropDown1.frame = CGRect(x: 0, y:0, width: self.view.frame.width, height: self.view.frame.height)
    dropDown1.center = CGPoint(x: self.view.frame.midX, y: self.view.frame.midY)

If there is a way to use your original code but specify the width so that self.frame.width is not dependent on the Storyboard "view as" device type then could you please tell me how to do that?

AussieSam avatar Sep 21 '18 01:09 AussieSam