小编Pet*_*ete的帖子

UIView背景颜色总是黑色

当我UIView以编程方式添加到视图控制器时,我无法将背景颜色更改为任何其他颜色,它始终保持黑色.

- (void)drawRect:(CGRect)rect
{
    // Drawing code
    self.backgroundColor = [UIColor blueColor];

    UIBezierPath *path = [[UIBezierPath alloc] init];
    [path moveToPoint:CGPointMake(100, 33)];
    [path addLineToPoint:CGPointMake(200, 33)];
    path.lineWidth = 5;
    [[UIColor redColor] setStroke];
    [path stroke];
}
Run Code Online (Sandbox Code Playgroud)

当我注释掉drawrect:并添加self.backgroundColor = [UIColor blueColor];到初始化程序时,颜色会发生变化:

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor blueColor]
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

为什么这个以及我需要改变什么?其实我希望背景是透明的.

objective-c uiview ios

20
推荐指数
2
解决办法
1万
查看次数

Swift字符串中的换行符和/或回车符

我试图在UITextView中添加换行符或回车符.

    var text = UITextField()
    text.text = "This is a text \r\n This is a text"
Run Code Online (Sandbox Code Playgroud)

结果显示整行文字在一行:

这是一个文本这是一个文本

是不是可以在UITextView中执行换行符或CR?或者我在这里缺少什么?

newline carriage-return uitextview ios swift

3
推荐指数
1
解决办法
5991
查看次数

UISearchController - 键盘未显示

我正在使用 UISearchController 并且搜索功能除了两件事外都有效。也许它们是相关的: a) 键盘不显示。所以我不能按“搜索”按钮 b) 在我的主 TableView 中,我访问了样式为“副标题”的原型单元格。搜索进行时,显示的单元格为“基本”样式。在这两种情况下(TableViewController 和 SearchViewController),我使用相同的单元格标识符。

有任何想法吗?这里的一些代码:

class OverviewTableViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let resultsController = SearchResultsController()
        resultsController.birds = birds
        searchController = UISearchController(searchResultsController: resultsController)
        //searchController.dimsBackgroundDuringPresentation = true

        let searchBar = searchController.searchBar
        searchBar.scopeButtonTitles = ["One", "Two"]
        searchBar.placeholder = "Search"
        searchBar.sizeToFit()
        tableView.tableHeaderView = searchBar
        searchController.searchResultsUpdater = resultsController
Run Code Online (Sandbox Code Playgroud)

第二类:

class SearchResultsController: UITableViewController, UISearchResultsUpdating {

    var items: [Item] = []
    var filtered: [Item] = []

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
}

// MARK: …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift uisearchcontroller

2
推荐指数
1
解决办法
1475
查看次数

使用带有unichar和String的二元运算符

我试图使用二元运算符来比较两个值:

character = (xxx as NSString).characterAtIndex(2)
if character == "1" {
    //do this thingy   
}
Run Code Online (Sandbox Code Playgroud)

现在我收到失败消息Binary Operator'=='不能应用于unichar或String类型的操作数.我也试图转换角色:

if String(character) == "1" 
Run Code Online (Sandbox Code Playgroud)

不起作用......

binary-operators unichar ios swift

2
推荐指数
1
解决办法
1428
查看次数