Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set fixed size to Image

How can I set a fixed size for an Image in SwiftUI? Currently my Image is really big

At the moment I have this structure:

struct TweetCell: View {
     var profileImage: Image
     var body: some View {
         HStack {
              profileImage
             VStack {
            ...
         }
    }
  }
}
like image 809
SwiftiSwift Avatar asked Jun 04 '19 22:06

SwiftiSwift


People also ask

How do I change the size of an image?

In the drop-down menu, choose the format you want your images to be converted to. You can also use the DPI to change the image size when it comes to printing. Click on "Start" to resize your photo. This tool changes the width and height of your file. If you only want to lower the file size, head over to Compress Image How do I resize an image?

How to resize an image in HTML?

One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag. These values specify the height and width of the image element. The values are set in px i.e. CSS pixels.

What is fixed fixed-size in image view?

Fixed-size is the fixed size which can not be decreased or increased by default it is not set to the image view. Syntax: ImageView (parent=None, name=’ImageView’, view=None, imageItem=None, levelMode=’mono’, *args)

How to make the image take the width of the container?

Try width:inherit to make the image take the width of it's container <div>. It will stretch/shrink it's height to maintain proportion. Don't set the height in the <div>, it will size to fit the image height. img { width:inherit; } .item { border:1px solid pink; width: 120px; float: left; margin: 3px; padding: 3px; }


Video Answer


2 Answers

One way of doing it is via

profileImage.resizable().frame(width: 50, height: 50)
like image 66
tsp Avatar answered Oct 10 '22 09:10

tsp


There are multiple ways to set fixed size to Image

1) Image("yourImage").frame(width: 25, height: 25, alignment: .center)

2) Image("yourImage").resizable().frame(width: 25, height: 25, alignment: .center)
3) Image("yourImage").frame(width: 25, height: 25, alignment: .center).clipped()

Attached the screenshots for all.

image1

image2

image3

like image 1
CrazyPro007 Avatar answered Oct 10 '22 10:10

CrazyPro007