Tuesday, June 9, 2026
HomeiOS Developmentios - Drawback with offset and buttons in SwiftUI?

ios – Drawback with offset and buttons in SwiftUI?

[ad_1]

It is a easy mistake, that every one SwiftUI devs have made numerous occasions. You are modifying the label, however not the precise button itself. Merely transfer the modifier to the Button.

Button (motion: {}, label: {
            Textual content(playing cards[index])
                .font(.title)
                .fontWeight(.daring)
            })
             .rotationEffect(Angle(radians: angle + Double.pi/2))
             .offset(x: xOffset, y: yOffset)

In SwiftUI almost every part is a View and might be handled as such. A button, additionally a view, can have a lot of the identical modifiers {that a} Textual content can have. In your query, you made a change to the inside view of the button, and never the precise button itself. That is why whenever you had been clicking within the center, it appeared to not be positioned proper, however the truth is it did precisely what you instructed it too. That is a crucial factor to recollect as a result of you may really push, pull, and offset issues exterior of the view which makes for some attention-grabbing layouts; Layouts resembling side-menus, or modals.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments