我的登录视图有一个子视图,其中有一个UIActivityView
和一个UILabel
说"登录...".此子视图的拐角不是圆角.我怎样才能让它们成圆形?
有没有办法在我的xib中做到这一点?
有没有办法cornerRadius
只设置一个左上角和右上角UIView
?
我尝试了以下内容,但最终没有看到视图了.
UIView *view = [[UIView alloc] initWithFrame:frame];
CALayer *layer = [CALayer layer];
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRoundedRect:frame byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) cornerRadii:CGSizeMake(3.0, 3.0)];
layer.shadowPath = shadowPath.CGPath;
view.layer.mask = layer;
Run Code Online (Sandbox Code Playgroud) 这是一个非常直接的问题 - 如何使用 SwiftUI 仅将边框效果应用于图像的所需边缘?
例如,我只想在图像的顶部和底部边缘应用边框,因为图像占据了整个屏幕宽度。
Image(mission.missionImageString)
.resizable()
.aspectRatio(contentMode: .fit)
.border(Color.white, width: 2) //Adds a border to all 4 edges
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏!
我想在 SwiftUI 中的形状(例如方形)中添加文本(例如 Hi)并使它们充当单个对象。
看起来没有直接的方法可以在 SwiftUI 中添加形状中的文本。
我有一个使用 SwiftUI 在 iOS 13 上完美显示的按钮列表,但在 iOS 14 上它会在屏幕结束的地方切断内容。
关于 HStacks 如何呈现屏幕上没有的内容,有什么改变吗?我曾经滚动并能够看到所有按钮。
我将附上一些屏幕截图和代码。
var body: some View {
VStack(alignment: .leading, spacing: 0){
Text("Select a venue type")
.font(.custom("MavenProBold", size: 16))
.padding(.leading, 16)
.padding(.top, 18)
.foregroundColor(Color.black)
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .center, spacing: 4, content: {
Button(action: {
self.selectedButtonIndex = 0
})
{
VStack(alignment: .center, spacing: 0, content: {
ZStack(alignment: .bottomTrailing){
Image(systemName: "star.fill")
.frame(width: circleFrameSize, height: circleFrameSize, alignment: .center)
.font(.title)
.background(Color(hexString: "#1A88FF"))
.foregroundColor(Color.white)
.clipShape(Circle())
}
Text("Things to do")
.padding(.top, 8)
.font(.custom("MavenProBold", size: …
Run Code Online (Sandbox Code Playgroud) 你好呀。我想知道,在 SwiftUI 中,如何屏蔽圆角矩形的内容,以便子矩形剪辑角。
在我的示例中,我在 zstack 上有一个白色圆角矩形和一个粉红色矩形,我尝试应用裁剪,但粉红色矩形不符合边角。
我试过将 .mask 应用于白色矩形,但它给出了与预期不同的结果(有时它不显示粉红色矩形)。
我确实找到了一个示例,您可以在其中设置自己的cornerRadius Round Specific Corners SwiftUI
但我想知道是否有办法掩盖粉红色矩形的内部/主体,使其符合父级的圆角矩形?
我的代码如下;
var body: some View {
GeometryReader { geometry in
Color.gray
.edgesIgnoringSafeArea(.top)
.overlay(
ZStack (alignment: .topLeading) {
RoundedRectangle(cornerRadius: 16,
style: .continuous)
.foregroundColor(.white)
.shadow(radius: 10)
// Tried using .mask here
Rectangle()
.fill(Color.pink)
.frame(minWidth: 0, maxWidth: .infinity, maxHeight: 150, alignment: .top)
.clipped()
}
.frame(width: 300, height: 450, alignment: .center)
)
}
.edgesIgnoringSafeArea(.all)
}
Run Code Online (Sandbox Code Playgroud)
编辑:澄清:
粉红色矩形应保持为矩形,但剪裁左上方和右上方以匹配父白色圆角矩形。
我一直在尝试弄清楚如何在Mac 应用程序中圆化SwiftUI 的特定角。我能找到的所有解决方案(例如这个)仅适用于 iOS,因为它具有. 我找不到同等的东西。View
UIRectCorner
NSRectCorner
以前,我会NSView
像这样绕过一个特定的角:
layer?.cornerRadius = 5
layer?.maskedCorners = .layerMinXMinYCorner //Bottom-left corner
Run Code Online (Sandbox Code Playgroud)
有没有人找到一种方法可以在 SwiftUI 中的 Mac 应用程序中圆化特定的角?
swiftui ×5
ios ×4
cocoa-touch ×2
swift ×2
uiview ×2
appkit ×1
cornerradius ×1
image ×1
macos ×1
mask ×1
round-rect ×1
swift5 ×1
uiimage ×1