我可以更改 UIActivityIndi​​cator 的大小吗?

发布于 2024-08-28 16:31:38 字数 719 浏览 9 评论 0原文

无论我在分配时给它什么大小,它都只显示固定大小。可以增加吗?

代码:

activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:
                     CGRectMake(142.00, 212.00, 80.0, 80.0)];
[[self view] addSubview:activityIndicator];
[activityIndicator sizeToFit];
activityIndicator.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
                                      UIViewAutoresizingFlexibleRightMargin |
                                      UIViewAutoresizingFlexibleTopMargin |
                                      UIViewAutoresizingFlexibleBottomMargin);
activityIndicator.hidesWhenStopped = YES;
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;

Whatever size i give to it while allocation, it shows fixed size only. Is it possible to increase it?

Code:

activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:
                     CGRectMake(142.00, 212.00, 80.0, 80.0)];
[[self view] addSubview:activityIndicator];
[activityIndicator sizeToFit];
activityIndicator.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
                                      UIViewAutoresizingFlexibleRightMargin |
                                      UIViewAutoresizingFlexibleTopMargin |
                                      UIViewAutoresizingFlexibleBottomMargin);
activityIndicator.hidesWhenStopped = YES;
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

小忆控 2024-09-04 16:31:38

下面将创建一个 15px 宽的活动指示器:

#import <QuartzCore/QuartzCore.h>

...

UIActivityIndicatorView *activityIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
activityIndicator.transform = CGAffineTransformMakeScale(0.75, 0.75);
[self addSubview:activityIndicator];

虽然我理解 TechZen 答案的观点,但我不认为以相对较小的量调整 UIActivityIndi​​cator 的大小确实违反了 Apple 的标准化界面习惯用法 - 无论活动指示器是20px 或 15px 不会改变用户对正在发生的事情的解释。

The following will create an activity indicator 15px wide:

#import <QuartzCore/QuartzCore.h>

...

UIActivityIndicatorView *activityIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
activityIndicator.transform = CGAffineTransformMakeScale(0.75, 0.75);
[self addSubview:activityIndicator];

While I understand the sentiment of TechZen's answer, I don't think adjusting the size of a UIActivityIndicator by a relatively small amount is really a violation of Apple's standardized interface idioms - whether an activity indicator is 20px or 15px won't change a user's interpretation of what's going on.

七婞 2024-09-04 16:31:38

Swift 3.0 和斯威夫特4.0

self.activityIndi.transform = CGAffineTransform(scaleX: 3, y: 3)

Swift 3.0 & Swift 4.0

self.activityIndi.transform = CGAffineTransform(scaleX: 3, y: 3)
不顾 2024-09-04 16:31:38

尺寸由款式决定。它是一个标准化的界面元素,因此 API 不喜欢摆弄它。

但是,您可能可以对其进行缩放变换。然而,不确定这会如何影响它的视觉效果。

仅从 UI 设计的角度来看,通常最好不要理会这些常见的标准化元素。用户被告知某些元素以一定的尺寸出现并且它们意味着特定的事物。改变标准外观会改变界面语法并使用户感到困惑。

The size is fixed by the style. It's a standardized interface element so the API doesn't like to fiddle with it.

However, you probably could do a scaling transform on it. Not sure how that would affect it visually, however.

Just from a UI design perspective, its usually better to leave these common standardized elements alone. User have been taught that certain elements appear in a certain size and that they mean specific things. Altering the standard appearance alters the interface grammar and confuses the user.

坚持沉默 2024-09-04 16:31:38

可以调整 UIActivityIndi​​cator 的大小。

CGAffineTransform transform = CGAffineTransformMakeScale(1.5f, 1.5f);
activityIndicator.transform = transform;

原始尺寸为1.0f。现在您可以相应地增加和减小尺寸。

It is possible to resize UIActivityIndicator.

CGAffineTransform transform = CGAffineTransformMakeScale(1.5f, 1.5f);
activityIndicator.transform = transform;

Original size is 1.0f. Now you increase and reduce size accordingly.

九命猫 2024-09-04 16:31:38

斯威夫特3

var activityIndicator = UIActivityIndicatorView()
activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)
activityIndicator.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
let transform: CGAffineTransform = CGAffineTransform(scaleX: 1.5, y: 1.5)
activityIndicator.transform = transform
activityIndicator.center = self.view.center
activityIndicator.startAnimating()
self.view.addSubview(activityIndicator)

Swift3

var activityIndicator = UIActivityIndicatorView()
activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)
activityIndicator.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
let transform: CGAffineTransform = CGAffineTransform(scaleX: 1.5, y: 1.5)
activityIndicator.transform = transform
activityIndicator.center = self.view.center
activityIndicator.startAnimating()
self.view.addSubview(activityIndicator)
骄傲 2024-09-04 16:31:38

这是一个可以与 Swift 3.0 和 Swift 3.0 一起使用的扩展。检查以防止 0 缩放(或您想要禁止的任何值):

extension UIActivityIndicatorView {
    func scale(factor: CGFloat) {
        guard factor > 0.0 else { return }

        transform = CGAffineTransform(scaleX: factor, y: factor)
    }
}

像这样调用它以缩放到 40 pts (2x):

activityIndicatorView.scale(factor: 2.0)

Here is an extension that would work with Swift 3.0 & checks to prevent 0 scaling (or whatever value you want to prohibit):

extension UIActivityIndicatorView {
    func scale(factor: CGFloat) {
        guard factor > 0.0 else { return }

        transform = CGAffineTransform(scaleX: factor, y: factor)
    }
}

Call it like so to scale to 40 pts (2x):

activityIndicatorView.scale(factor: 2.0)
灰色世界里的红玫瑰 2024-09-04 16:31:38

还有许多其他有用的“CGAffineTransform”技巧可供您使用。有关更多详细信息,请参阅 Apple 开发人员库参考:

http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGAffineTransform/Reference/reference.html

祝你好运!

There also are lots of other useful "CGAffineTransform" tricks you can play with. For more details please see Apple Developer Library reference:

http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGAffineTransform/Reference/reference.html

Good luck!

一页 2024-09-04 16:31:38

您能做的最好的事情就是使用 whiteLarge 样式。
让我= UIActivityIndi​​catorView(activityIndi​​catorStyle:UIActivityIndi​​catorViewStyle.whiteLarge)。

正如您在这些图片中看到的那样,增加 UIActivityIndi​​catorView 的大小不会改变指示器的大小。小指示器“大”指示器

The best you can do is use the whiteLarge style.
let i = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.whiteLarge).

Increasing the size of UIActivityIndicatorView does not change the size of the indicator proper, as you can see in these pictures.small indicator"large" indicator

内心荒芜 2024-09-04 16:31:38

ActivityIndi​​cator.transform = CGAffineTransform(scaleX: 1.75, y: 1.75);

这对我改变指标的大小很有帮助。

activityIndicator.transform = CGAffineTransform(scaleX: 1.75, y: 1.75);

This worked me for transforming size of indicator .

三人与歌 2024-09-04 16:31:38

是的,正如已经回答的那样,可以使用 Transform 属性更改 UIActivityIndi​​catorView 的可见大小。为了允许设置/获取精确的指示器大小,我添加了简单的扩展:

extension UIActivityIndicatorView {

var imageSize: CGSize {
    let imgView = subviews.first { $0 is UIImageView }
    return imgView?.bounds.size ?? .zero
}

var radius: CGFloat {
    get {
        imageSize.width * scale / 2.0
    }
    set {
        let w = imageSize.width
        scale = (w == 0.0) ? 0 : newValue * 2.0 / w
    }
}

var scale: CGFloat {
    get {
        // just return x scale component as this var has meaning only
        // if transform of scale type, and x and y scales are same)
        transform.a
    }
    set {
        transform = CGAffineTransform(scaleX: newValue, y: newValue);
    }
}

}

使用此扩展,您可以简单地编写例如,

indicatorView.radius = 16.0

当您需要从其他视图设置指示器的精确间距(因为 UIActivityIndi​​catorView 具有零帧)时,它也很有用。

Yes, as it is already answered, visible size of UIActivityIndicatorView can be changed using transform property. To allow set/get exact indicator size, I have added simple extension:

extension UIActivityIndicatorView {

var imageSize: CGSize {
    let imgView = subviews.first { $0 is UIImageView }
    return imgView?.bounds.size ?? .zero
}

var radius: CGFloat {
    get {
        imageSize.width * scale / 2.0
    }
    set {
        let w = imageSize.width
        scale = (w == 0.0) ? 0 : newValue * 2.0 / w
    }
}

var scale: CGFloat {
    get {
        // just return x scale component as this var has meaning only
        // if transform of scale type, and x and y scales are same)
        transform.a
    }
    set {
        transform = CGAffineTransform(scaleX: newValue, y: newValue);
    }
}

}

With this extension you can simply write for example

indicatorView.radius = 16.0

It is also useful when you need to set exact spacing of indicator from some other view as UIActivityIndicatorView has zero frame.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文