awakefromnib有一个字符串s,查找字符串s是否在字符串中t,如果有返回重复的个数,C语言或者Objective-C变成

awakefromnib  时间:2021-07-05  阅读:()

如何在UITextView中添加默认文字

在UITextField中自带placeholder属性,可以用于提示输入框信息。

但是UITextView并不具备此功能 介绍两种方法来实现: 第一种: 初始化UITextView //首先定义UITextView UITextView *textView = [[UITextView alloc] init]; textView.font = [UIFont systemFontOfSize:14]; textView.frame =CGRectMake(10, 0, cell.contentView.bounds.size.width-20, side); textView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; textView.backgroundColor = [UIColor whiteColor]; [cell.contentView addSubview:textView]; textView.hidden = NO; textView.delegate = self; //其次在UITextView上面覆盖个UILable,UILable设置为全局变量。

uilabel.frame =CGRectMake(17, 8, cell.contentView.bounds.size.width - side+10, 20); uilabel.text = @"请填写审批意见..."; uilabel.enabled = NO;//lable必须设置为不可用 uilabel.backgroundColor = [UIColor clearColor]; [cell.contentView addSubview:uilabel]; 实现UITextView的代理 -(void)textViewDidChange:(UITextView *)textView { self.examineText = textView.text; if (textView.text.length == 0) { uilabel.text = @"请填写审批意见..."; }else{ uilabel.text = @""; } } 第二种: UITextView 实现 placeholder 及隐藏键盘 #import @interface UIPlaceHolderTextView : UITextView { NSString *placeholder; UIColor *placeholderColor; @private UILabel *placeHolderLabel; } @property(nonatomic, retain) UILabel *placeHolderLabel; @property(nonatomic, retain) NSString *placeholder; @property(nonatomic, retain) UIColor *placeholderColor; -(void)textChanged:(NSNotification*)notification; @end #import "UIPlaceHolderTextView.h" @implementation UIPlaceHolderTextView @synthesize placeHolderLabel; @synthesize placeholder; @synthesize placeholderColor; - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [placeHolderLabel release]; placeHolderLabel = nil; [placeholderColor release]; placeholderColor = nil; [placeholder release]; placeholder = nil; [super dealloc]; } - (void)awakeFromNib { [super awakeFromNib]; [self setPlaceholder:@""]; [self setPlaceholderColor:[UIColor lightGrayColor]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged:) name:UITextViewTextDidChangeNotification object:nil]; } - (id)initWithFrame:(CGRect)frame { if( (self = [super initWithFrame:frame]) ) { [self setPlaceholder:@""]; [self setPlaceholderColor:[UIColor lightGrayColor]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged:) name:UITextViewTextDidChangeNotification object:nil]; } return self; } - (void)textChanged:(NSNotification *)notification { if([[self placeholder] length] == 0) { return; } if([[self text] length] == 0) { [[self viewWithTag:999] setAlpha:1]; } else { [[self viewWithTag:999] setAlpha:0]; } } - (void)setText:(NSString *)text { [super setText:text]; [self textChanged:nil]; } - (void)drawRect:(CGRect)rect { if( [[self placeholder] length] > 0 ) { if ( placeHolderLabel == nil ) { placeHolderLabel = [[UILabel alloc] initWithFrame:CGRectMake(8,8,self.bounds.size.width - 16,0)]; placeHolderLabel.lineBreakMode = UILineBreakModeWordWrap; placeHolderLabel.numberOfLines = 0; placeHolderLabel.font = self.font; placeHolderLabel.backgroundColor = [UIColor clearColor]; placeHolderLabel.textColor = self.placeholderColor; placeHolderLabel.alpha = 0; placeHolderLabel.tag = 999; [self addSubview:placeHolderLabel]; } placeHolderLabel.text = self.placeholder; [placeHolderLabel sizeToFit]; [self sendSubviewToBack:placeHolderLabel]; } if( [[self text] length] == 0 && [[self placeholder] length] > 0 ) { [[self viewWithTag:999] setAlpha:1]; } [super drawRect:rect]; } @end //隐藏键盘,实现UITextViewDelegate -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text { if ([text isEqualToString:@" "]) { [m_textView resignFirstResponder]; return NO; } return YES; }

storyboard中定义的view的坐标和大小,用代码改变大小时,是不是改变不了

1. 建一个 UIView的子类(MyView.h/MyView.m) 2. 建一个 View类型的XIB 3. 把xib的file‘s owner设为MyView 4. 在.h文件里加上 @property (nonatomic, retain) IBOutlet UIView *contentView;   5.绑定xib里的根view到.h里的 contentView 6.在.m里加上   - (void)awakeFromNib { NSLog(@"awake from nib"); [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil]; [self addSubview:self.contentView]; }   ok了。

storyboard里用的时候把UIView的类名改为MyView就可以。

xib和.h可以互相绑定子outlet什么的。

关于控制view的UIView.m类的请教

如果你是用initwithframe创建的view,你就自己写个initwithframe。

- (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { // Initialization code } return self;}如果你是用interface builder拽的view,用下面的肯定可以-(void)awakeFromNib{}

有一个字符串s,查找字符串s是否在字符串中t,如果有返回重复的个数,C语言或者Objective-C变成

返回值如果为0 说明没找到 #import "find.h" @implementation find - (void)awakeFromNib { NSString *str1 = @"tststststssststststst"; NSString *str2 = @"s"; int iCount = [self findTheString:str2 FromString:str1]; NSLog(@"%d",iCount); } - (int)findTheString:(NSString *)str1 FromString:(NSString *)str2 { NSArray *array = [ponentsSeparatedByString:str1]; return [array count] - 1; } @end

印象云七夕促销,所有机器7折销售,美国CERA低至18元/月 年付217元!

印象云,成立于2019年3月的商家,公司注册于中国香港,国人运行。目前主要从事美国CERA机房高防VPS以及香港三网CN2直连VPS和美国洛杉矶GIA三网线路服务器销售。印象云香港三网CN2机房,主要是CN2直连大陆,超低延迟!对于美国CERA机房应该不陌生,主要是做高防服务器产品的,并且此机房对中国大陆支持比较友好,印象云美国高防VPS服务器去程是163直连、三网回程CN2优化,单IP默认给20...

ProfitServer折优惠西班牙vps,荷兰vps,德国vps,5折优惠,不限制流量

profitserver正在对德国vps(法兰克福)、西班牙vps(马德里)、荷兰vps(杜廷赫姆)这3处数据中心内的VPS进行5折优惠促销。所有VPS基于KVM虚拟,纯SSD阵列,自带一个IPv4,不限制流量,在后台支持自定义ISO文件,方便大家折腾!此外还有以下数据中心:俄罗斯(多机房)、捷克、保加利亚、立陶宛、新加坡、美国(洛杉矶、锡考克斯、迈阿密)、瑞士、波兰、乌克兰,VPS和前面的一样性...

俄罗斯vps主机推荐,怎么样俄罗斯vps俄罗斯vps速度怎么样?

俄罗斯vps速度怎么样?俄罗斯vps云主机节点是欧洲十大节点之一,地处俄罗斯首都莫斯科,网络带宽辐射周边欧洲大陆,10G专线连通德国法兰克福、法国巴黎、意大利米兰等,向外连接全球。俄罗斯vps云主机速度快吗、延迟多少?由于俄罗斯数据中心出口带宽充足,俄罗斯vps云主机到全球各地的延迟、速度相对来说都不错。今天,云服务器网(yuntue.com)小编介绍一下俄罗斯vps速度及俄罗斯vps主机推荐!俄...

awakefromnib为你推荐
元宝网vap数字资产是不是传销洗牌算法我是小白,eclipse说老式声明,怎么办?帮我看下,不胜感激!! //发牌算法oracle索引oracle表加索引有什么用? 请举一个例子说明谢谢电子日历怎样调整电子日历上的时间jqlDX5JQL8WDPMW求大神帮查下是不是行货苹果调度系统生产调度系统丁奇赛尔号丁奇技能表,带等级,刷什么学习力好?数秦科技数秦科技旗下有哪些区块链项目?ruby语言公司实习让我学习RUBY语言,不知道RUBY语言发展前景怎么样,值不值的去学习。数据分析报告范文如何写数据分析报告?
猫咪av永久最新域名 电信服务器租赁 VPS之家 老左 56折 贵州电信宽带测速 万网优惠券 湖南服务器托管 建立邮箱 常州联通宽带 银盘服务 无限流量 空间登入 免费的asp空间 免费ftp 大化网 网站防护 第八届中美互联网论坛 空间排行榜 发证机构 更多