Cannot assign to property: 'width' is a get-only property
You need to set the width
of the frame's size
property.
cell.reciverMsg.frame.size.width = 20
The width
property of frame
is just a read-only convenience. See the documentation for CGRect
for details.
SwiftUI Pass Value from Geometry Reader to Function
Is there a way to pass the value calculated by GeometryReader to a function?
Yes, you can do this. The var metrics
is a GeometryProxy
, so function signature should be like in the following example
private func resizedImage(for metrics: GeometryProxy) -> some View {
self.image
.resizable()
.frame(width: (metrics.size.height - 10) * 0.561403509 , height: metrics.size.height - 10, alignment: .top)
.clipped()
}
so your usage
GeometryReader { metrics in
ZStack{
self.resizedImage(for: metrics)
}
}
Update: for changed request
Assuming you have in child view binding as
@Binding var cropSize: CGSize
the above function can be modified as follow
private func resizedImage(for metrics: GeometryProxy) -> some View {
let size = CGSize(width: (metrics.size.height - 10) * 0.561403509,
height: metrics.size.height - 10)
self.cropSize = size
return self.image
.resizable()
.frame(width: size.width, height: size.height, alignment: .top)
.clipped()
}
UIImageView frame not placing correctly on the parent ImageView
You're using frame sizes before the frames are finished being set by auto-layout.
I'd suggest using constraints, but if you want to stick to frame coordinates...
- add the "round plus" icon imageView in
viewDidLoad()
- set its
frame.origin
inviewDidLayoutSubviews()
orviewDidAppear()
Incorrect frame size inside UITextfield Subclass in swift3
TextField
is getting it's frame from the storyboard so you are getting incorrect frame size while setting cornerRadius.
You have error while setting the corner radius.
self.layer.cornerRadius = self.frame.size.height / 2
Replace this with
self.layer.cornerRadius = 2
Or also better if you override drawRect
method and set cornerRadius as
override func draw(_ rect: CGRect) {
self.layer.cornerRadius = rect.size.height / 2
}
Resize image in asp.net Size readonly error
It is read-only; you'll have to create a new bitmap from it. Try this: -
internal static Image ScaleByPercent(Image image, Size size, float percent)
{
int sourceWidth = image.Width,
sourceHeight = image.Height;
int destWidth = (int)(sourceWidth * percent),
destHeight = (int)(sourceHeight * percent);
if (destWidth <= 0)
{
destWidth = 1;
}
if (destHeight <= 0)
{
destHeight = 1;
}
var resizedImage = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb);
resizedImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
// get handle to new bitmap
using (var graphics = Graphics.FromImage(resizedImage))
{
InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
// create a rect covering the destination area
var destRect = new Rectangle(0, 0, destWidth, destHeight);
var brush = new SolidBrush(drawing.Color.White);
graphics.FillRectangle(brush, destRect);
// draw the source image to the destination rect
graphics.DrawImage(image,
destRect,
new Rectangle(0, 0, sourceWidth, sourceHeight),
GraphicsUnit.Pixel);
}
return resizedImage;
}
This is from a site I have in production; if you want I can send you the code that works out how to keep the correct aspect ratio when resizing (i.e. what gets passed in the 'size' parameter)
Hope that helps
Related Topics
Does Kotlin Has Extension Class to Interface Like Swift
Uisplitviewcontroller Displaymodebuttonitem()
Subclass Nsapplication in Swift
Is There Any Way of Locking an Object in Swift Like in C#
Swift Error: Missing Argument Label 'Name:' in Call
Reversing the Order of a String Value
Early Return from a Void-Func in Swift
How to Get Date and Time to Show a Clock in Uilabel
Open a Viewcontroller from Remote Notification
Reading an Inputstream into a Data Object
Subclass.Fetchrequest() Swift 3.0, Extension Not Really Helping 100%
"Ambiguous Use of 'Propertyname'" Error Given Overridden Property with Didset Observer
Target Parameter in Dispatchqueue
Macos/Swift Capture Audio with Avcapturesession