gpt4 book ai didi

iphone - 将 UISearchBar 中的 BookmarkButton 替换为 Activityindicator

转载 作者:行者123 更新时间:2023-12-03 19:28:08 27 4
gpt4 key购买 nike

我使用 UISearchBar 输入地址来建立网络连接。建立连接后,我想显示事件指示器,而不是搜索栏右侧的小书签按钮。据我所知,没有公开声明的属性可以让我访问搜索栏的正确 subview 。我已经看到了这一点,有什么想法吗?

最佳答案

在搜索或连接正在进行时,将左侧的搜索图标替换为事件指示器怎么样?

SearchBarWithActivity.h:

#import <UIKit/UIKit.h>

@interface SearchBarWithActivity : UISearchBar

- (void)startActivity; // increments startCount and shows activity indicator
- (void)finishActivity; // decrements startCount and hides activity indicator if 0

@end

SearchBarWithActivity.m:

#import "SearchBarWithActivity.h"

@interface SearchBarWithActivity()

@property(nonatomic) UIActivityIndicatorView *activityIndicatorView;
@property(nonatomic) int startCount;

@end


@implementation SearchBarWithActivity

- (void)layoutSubviews {
UITextField *searchField = nil;

for(UIView* view in self.subviews){
if([view isKindOfClass:[UITextField class]]){
searchField= (UITextField *)view;
break;
}
}

if(searchField) {
if (!self.activityIndicatorView) {
UIActivityIndicatorView *taiv = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
taiv.center = CGPointMake(searchField.leftView.bounds.origin.x + searchField.leftView.bounds.size.width/2,
searchField.leftView.bounds.origin.y + searchField.leftView.bounds.size.height/2);
taiv.hidesWhenStopped = YES;
taiv.backgroundColor = [UIColor whiteColor];
self.activityIndicatorView = taiv;
[taiv release];
_startCount = 0;

[searchField.leftView addSubview:self.activityIndicatorView];
}
}

[super layoutSubviews];
}

- (void)startActivity {
self.startCount = self.startCount + 1;
}

- (void)finishActivity {
self.startCount = self.startCount - 1;
}

- (void)setStartCount:(int)startCount {
_startCount = startCount;
if (_startCount > 0)
[self.activityIndicatorView startAnimating];
else {
[self.activityIndicatorView stopAnimating];
}
}

@end

关于iphone - 将 UISearchBar 中的 BookmarkButton 替换为 Activityindicator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1209842/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com