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

青云互联19元/月,美国洛杉矶CN2GIA/香港安畅CN2云服务器低至;日本云主机

青云互联怎么样?青云互联美国洛杉矶cn2GIA云服务器低至19元/月起;香港安畅cn2云服务器低至19元/月起;日本cn2云主机低至35元/月起!青云互联是一家成立于2020年的主机服务商,致力于为用户提供高性价比稳定快速的主机托管服务。青云互联本站之前已经更新过很多相关文章介绍了,青云互联的机房有香港和洛杉矶,都有CN2 GIA线路、洛杉矶带高防,商家承诺试用7天,打死全额退款点击进入:青云互联...

星梦云-100G高防4H4G21M月付仅99元,成都/雅安/德阳

商家介绍:星梦云怎么样,星梦云好不好,资质齐全,IDC/ISP均有,从星梦云这边租的服务器均可以备案,属于一手资源,高防机柜、大带宽、高防IP业务,一手整C IP段,四川电信,星梦云专注四川高防服务器,成都服务器,雅安服务器,。活动优惠促销:1、成都电信夏日激情大宽带活动机(封锁UDP,不可解封):机房CPU内存硬盘带宽IP防护流量原价活动价开通方式成都电信优化线路2vCPU2G40G+60G21...

香港 1核1G 29元/月 美国1核 2G 36元/月 快云科技

快云科技: 11.11钜惠 美国云机2H5G年付148仅有40台,云服务器全场7折,香港云服务器年付388仅不到五折 公司介绍:快云科技是成立于2020年的新进主机商,持有IDC/ICP/ISP等证件资质齐全主营产品有:香港弹性云服务器,美国vps和日本vps,香港物理机,国内高防物理机以及美国日本高防物理机官网地址:www.345idc.com活动截止日期为2021年11月13日此次促销活动提供...

awakefromnib为你推荐
诺诺云代账诺诺云代账系统好用吗?有同行的分享下经验不?公司准备换个财务系统。图片地址如何根据一张图片的地址找到它在哪发的fcloseC语言fclose错误最开放的浏览器网页浏览器有哪些啊?查字网騳骉,怎样读?拼音备忘录模式为什么我的华为手机界面总是有个框框在备忘录上面jql建筑设计图纸上JQL 梁,是不是地下正负零基础梁?急急!jqlDX5JQL8WDPMW求大神帮查下是不是行货苹果保留两位有效数字物理中保留两位有效数字是保留小数点后的两位还是从小数点前不是0的数开始保留两位?php论坛怎样快速在个人电脑上建立一个自己的PHP论坛服务器?
双线服务器租用 budgetvm 搬瓦工官网 163网 表单样式 网站保姆 免费名片模板 52测评网 上海域名 seednet 免费测手机号 福建铁通 smtp虚拟服务器 永久免费空间 注册阿里云邮箱 登陆qq空间 聚惠网 gotoassist 连连支付 paypal登陆 更多