# How to set height and width in proportion with superview in SwiftUI?

**URL:** <https://forums.kodeco.com/t/how-to-set-height-and-width-in-proportion-with-superview-in-swiftui/84220>\
**Category:** Swift\
**Created:** [October 8, 2019, 7:21am UTC](https://forums.kodeco.com/t/how-to-set-height-and-width-in-proportion-with-superview-in-swiftui/84220 "2019-10-08T07:21:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vimipatel](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/vimipatel/32/83106_2.png) [@vimipatel](https://forums.kodeco.com/u/vimipatel)\
**Post date:** [October 8, 2019, 7:21am UTC](https://forums.kodeco.com/t/how-to-set-height-and-width-in-proportion-with-superview-in-swiftui/84220/1 "2019-10-08T07:21:07Z")

</div>

I want to know that is it possible to adjust `height` and `width` in proportion according to superview in `SwiftUI` to any `UIControl` ?

As we are doing like :

```
let txtFld = UITextField()
txtFld.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: self.view.frame.width/2, height: self.view.frame.height*0.1))

```

I know we can somehow achieve to adjust width by using `Spacer()`, `.padding` and `edgeInsets`. But what about `height`? I have seen lots of tutorial for `SwiftUI`, everywhere `height` is static. Even on Apple’s site. [SwiftUI Tutorials](https://developer.apple.com/tutorials/swiftui/creating-and-combining-views#compose-the-detail-view)

If anyone have knowledge about how to set height in proportion with view’s height, please share here. Because at some point we need like that. For ex. If it needs to make button according to device height. (Let’s say in iPhone SE = 40, iPhone 8P = 55, iPhone X = 65)

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [November 14, 2019, 10:38am UTC](https://forums.kodeco.com/t/how-to-set-height-and-width-in-proportion-with-superview-in-swiftui/84220/2 "2019-11-14T10:38:10Z")

</div>

@vimipatel Do you still have issues with this?

---

<div class="post-metadata">

**Author:** ![jayantvarma](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jayantvarma/32/111768_2.png) [@jayantvarma](https://forums.kodeco.com/u/jayantvarma)\
**Post date:** [November 15, 2019, 9:37am UTC](https://forums.kodeco.com/t/how-to-set-height-and-width-in-proportion-with-superview-in-swiftui/84220/3 "2019-11-15T09:37:42Z")

</div>

Hi @vimipatel,  
what you are looking for is a GeometryReader object. ([Apple Developer Documentation](https://developer.apple.com/documentation/swiftui/geometryreader))

cheers,

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [March 22, 2020, 11:21pm UTC](https://forums.kodeco.com/t/how-to-set-height-and-width-in-proportion-with-superview-in-swiftui/84220/4 "2020-03-22T23:21:11Z")

</div>

This topic was automatically closed after 166 days. New replies are no longer allowed.
