日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

如何创建圆角 UITextField 与内阴影

發(fā)布時間:2024/4/17 编程问答 56 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何创建圆角 UITextField 与内阴影 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本文轉(zhuǎn)自http://www.itstrike.cn/Question/9309fbd6-ef5d-4392-b361-a60fd0a3b18e.html

主要學習如何創(chuàng)建內(nèi)陰影

我自定義?UITextfield?,看起來像?UISearchbar?。

像做

self.back_textfield = [[UITextField alloc]initWithFrame:CGRectMake(5, 7, 310, 30)]; [self.back_textfield setBorderStyle:UITextBorderStyleRoundedRect]; self.back_textfield.layer.cornerRadius = 15.0;

但我看到這個:

正如您可以看到內(nèi)陰影不會按照邊界。

解決方法 1:

我猜背景上?UITextField?是一個圖像,所以它沒有按照你的圓角半徑。
創(chuàng)建內(nèi)部陰影是 iOS 中棘手的。你有 2 個選項。
1) 使用該圖像作為背景UITextField
2) 以編程方式設置陰影 (但它看起來的吸引力,比 1 選項)。

這里是從 @Matt Wilding 設置為文本字段與解決方案的圓內(nèi)陰影的代碼

_textField.layer.cornerRadius = 10.0f;CAShapeLayer* shadowLayer = [CAShapeLayer layer]; [shadowLayer setFrame:_textField.bounds];// Standard shadow stuff [shadowLayer setShadowColor:[[UIColor colorWithWhite:0 alpha:1] CGColor]]; [shadowLayer setShadowOffset:CGSizeMake(0.0f, 0.0f)]; [shadowLayer setShadowOpacity:1.0f]; [shadowLayer setShadowRadius:4];// Causes the inner region in this example to NOT be filled. [shadowLayer setFillRule:kCAFillRuleEvenOdd];// Create the larger rectangle path. CGMutablePathRef path = CGPathCreateMutable(); CGPathAddRect(path, NULL, CGRectInset(_textField.bounds, -42, -42));// Add the inner path so it's subtracted from the outer path. // someInnerPath could be a simple bounds rect, or maybe // a rounded one for some extra fanciness. CGPathRef someInnerPath = [UIBezierPath bezierPathWithRoundedRect:_textField.bounds cornerRadius:10.0f].CGPath; CGPathAddPath(path, NULL, someInnerPath); CGPathCloseSubpath(path);[shadowLayer setPath:path]; CGPathRelease(path);[[_textField layer] addSublayer:shadowLayer];CAShapeLayer* maskLayer = [CAShapeLayer layer]; [maskLayer setPath:someInnerPath]; [shadowLayer setMask:maskLayer];

別忘了要導入

#import <QuartzCore/QuartzCore.h>

總結(jié)

以上是生活随笔為你收集整理的如何创建圆角 UITextField 与内阴影的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。