Preventing the labels to be cutting off from the sides - TagsView
You are almost there.
Every Text
s have 16 points padding on each of their sides. And the VStack
has 16
points padding too. You need to consider them when calculating the width of the label.
let viewWidth = label.frame.size.width + 32
print("viewWidth = \(viewWidth)")
if (width + viewWidth + 32) < screenWidth {
width += viewWidth
print("width = \(width)")
tempItems.append(word)
}
You may calculate the spacing between every two Texts too.
SwiftUI iOS 14 Picker width can't be changed
The width: 10
is too small... anyway, use .clipped (or .clipShape) to restrict drawing outside bounds
Picker(selection: self.$position, label: Text("")){
ForEach(0..<50){ i in
Text("\(i)")
}
}
.frame(width: 50, height: 150, alignment: .center)
.clipped() // << here !!
UIDatePicker Cutting Off Text & Not Displaying Days
Ok, I figured it out. This happened as a result of trying to use UIAppearance on a tableView background color. This has nothing to do with tableViews on the face of it, but Apple must be using a tableView privately for the PickerViews. So, my attempt to set a UIAppearance via a category on a tableView background color seems to be doing something unexpected. Lesson learned. Don't try to use UIAppearance where they are not officially supported.
How to change UIPickerView width with multiple Pickers in SwiftUI?
You need to remove compression resistance priority
let picker = UIPickerView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
picker.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
and then can use any frame as you need in SwiftUI part (static or calculated)
MainPicker(pickerSelections: self.$selections)
.frame(width: 200)
Demo prepared & tested with Xcode 11.7 / iOS 13.7
Maximum lineheight cutting off text
After spending a few hours in the torture chamber I finally figured it out! The issue was the font itself. It was an .otf and not a .ttf. Because of this swift did not understand the font's internal lineheight and just cut it off. After switching to .ttf the issue was resolved
CGImageCreateWithImageInRect cutting off
CGImageCreateWithImageInRect(screenshot.CGImage, crop) does indeed return a cropped version. Here is the relevant comment from the documentation:
Quartz performs these tasks to create the subimage:
Adjusts the area specified by the rect parameter to integral bounds by calling the function CGRectIntegral.
Intersects the result with a rectangle whose origin is (0,0) and size is equal to the size of the image specified by the image parameter.
References the pixels within the resulting rectangle, treating the first pixel within the rectangle as the origin of the sub image.
A simple way to solve this is to adjust the position of the resulting UIImageView so it is correct for its size. Here is the relevant calculation:
let screenshotBounds = CGRectMake(0.0, 0.0, screenshot.size.width, screenshot.size.height)
let cropIntegral = CGRectIntegral(crop)
let cropIntersection = CGRectIntersection(cropIntegral, screenshotBounds)
bgImage.center = CGPoint(CGRectGetMidX(cropIntersection), CGRectGetMidY(cropIntersection))
cropIntersection is the bounding rectangle of our extracted image (following the first two steps given in the documentation). Therefore, we can use it to position the imageView to the same place in the original image.
How to change the Font size in UIPickerView?
You need to implement pickerView:viewForRow:forComponent:reusingView:
method in picker's delegate
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel* tView = (UILabel*)view;
if (!tView){
tView = [[UILabel alloc] init];
// Setup label properties - frame, font, colors etc
...
}
// Fill the label text here
...
return tView;
}
Related Topics
Draw Polyline Using Google Maps in Custom View with Swift 3
Using String.Characterview.Index.Successor() in for Statements
Adding an Skscene to a Uiviewcontroller
Apple Doesn't Recognize Imgur's Https
iOS Where to Put Custom Cell Design? Awakefromnib or Cellforrowatindexpath
Stick UItableview Header View to Top When Creating Header in Storyboard
How to Post Data Using Afnetworking 2.0
Convert Rgb Image to 1 Channel Image (Black/White)
How to Send Push Notification to Apns from iOS Device
Realm Crashes with Rlmexception: Object Has Been Deleted or Invalidated
iOS UIlabel Autoshrink So Word Doesn't Truncate to Two Lines
Atos Does Not Symbolicate System Frameworks/Libraries Properly
Box Shadow Spread Bug in Webkit in iOS 7 on Retina Ipads
Receive Signal from Beacon While App Is in the Background
How to Go to Specific Native View Controller from React-Native Code
Gcm Support for iOS Application When Application in Background or Killed