Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add padding to LabelView in swiftui does not work. #418

Open
arbyruns opened this issue Aug 17, 2022 · 1 comment
Open

Add padding to LabelView in swiftui does not work. #418

arbyruns opened this issue Aug 17, 2022 · 1 comment

Comments

@arbyruns
Copy link

I'm attempting to add padding to the label to present the run off as shown below. Here's how I'm calling the view within SwiftUI

SUILabel(text: tweet.text, preferredMaxLayoutWidth : UIScreen.main.bounds.width - 50)
                        .fixedSize(horizontal: false, vertical: true)

image

Here's the code I'm using,

struct SUILabel: UIViewRepresentable {
    @Environment(\.openURL) var openURL

    let text: String

    var preferredMaxLayoutWidth: CGFloat = UIScreen.main.bounds.width - 50
    func makeUIView(context: UIViewRepresentableContext<SUILabel>) -> UILabel {
        let label = ActiveLabel()
        label.layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 25)
        label.numberOfLines = 10
        label.enabledTypes = [.mention, .hashtag, .url]
        label.hashtagColor = .systemBlue
        label.mentionColor = .systemBlue
        label.URLColor = .systemBlue
        label.text = text
        label.textColor = UITraitCollection().userInterfaceStyle == .light ? .black : .white
        label.preferredMaxLayoutWidth = UIScreen.main.bounds.width
        label.contentMode = .scaleAspectFill

        // MARK: - handle types

        label.handleHashtagTap { hashtag in
            print("Success. You just tapped the \(hashtag) hashtag")
            openURL(URL(string: "https://twitter.com/hashtag/\(hashtag)")!)
        }
        label.handleURLTap { url in
            openURL(url)
        }
        label.handleMentionTap { handle in
            openURL(URL(string: "https://twitter.com/\(handle)")!)
        }
        return label
    }


    func updateUIView(_ uiView: UILabel, context: UIViewRepresentableContext<SUILabel>) { }
}
@brooksGetIt
Copy link

brooksGetIt commented Jul 24, 2023

set fixedSize(horizontal: true, vertical: true),and "label.preferredMaxLayoutWidth = UIScreen.main.bounds.width" will work for width.
your code helps a lot. thx bro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants