更改NSView的角半径应该是非常直接的但是我收到错误消息"致命错误:无法打开Optional.None".我是否有机会以10.9而不是10.10这样做,这是因为框架差异而发生的?或者代码错了.
class aRoundView: NSView {
let cornerRad = 5.0
init(frame: NSRect) {
super.init(frame: frame)
self.layer.cornerRadius = cornerRad
}
override func drawRect(dirtyRect: NSRect)
{
super.drawRect(dirtyRect)
NSColor.redColor().setFill()
NSRectFill(dirtyRect)
}
}
Run Code Online (Sandbox Code Playgroud)
叫它
func applicationDidFinishLaunching(aNotification: NSNotification?) {
let aView = mainViewTest(frame: NSMakeRect(0, 0, 100, 100))
self.window.contentView.addSubview(aView)
}
Run Code Online (Sandbox Code Playgroud)
实际上不仅如此.任何使用self.layer的迭代都会给出相同的结果,backgroundcolor等.
我刚刚开始使用 XCode。我已经安装了XVim插件来提供 Vim 键绑定。但是,我缺少打开相关行号的能力。在 vim 中,这是通过 完成的:set relativenumber,而在 Visual Studio 中,有一个插件。
XCode 5 有这样的东西吗?
我是iOS Dev的新手并且学习用户输入/输出.当用户被要求输入出生日期以查明用户活着多久时,我无法弄清楚如何显示mm/dd/yyyy的正确输出.
NSDate *actualDate = [[NSDate alloc]init];
NSDateComponents *comps = [[NSDateComponents alloc]init];
double getDays = [self.dayTextField.text doubleValue];
double getMonths = [self.monthTextField.text doubleValue];
double getYears = [self.yearTextField.text doubleValue];
NSCalendar *g = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *dateOfBirth = [g dateFromComponents:comps];
double secondsSinceEarlierDate = [actualDate timeIntervalSinceDate:dateOfBirth];
double minutes = secondsSinceEarlierDate/60;
double hours = minutes/60;
double weeks = days/7;
//Can not figure out these...
double days = hours/24;
double months = weeks * 0.229984378;
double years = months/12;
self.showMonthsLabel.text = [@(months) stringValye];
self.showDaysLabel.text = [@(days) …Run Code Online (Sandbox Code Playgroud) 在 c# 中,我可以创建函数可以返回任何类型的对象,例如
(ArrayList) funtionName()
{
return ArrayList;
}
Run Code Online (Sandbox Code Playgroud)
这在 Obj-c 中可能吗?谢谢。
为什么采用页脚视图?
-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
if(section == 0)
return 16;
return 16.0;
}
-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
return 0.0;
}
-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view=[[UIView alloc] initWithFrame:CGRectZero];
view.backgroundColor=[UIColor redColor];
return view;
}
-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view=[[UIView alloc] initWithFrame:CGRectZero];
view.backgroundColor=[UIColor yellowColor];
return view;
}
Run Code Online (Sandbox Code Playgroud)

我试图在iOS 8的UIStoryboard中使用swift创建自定义标签栏控制器(objective-c也没关系).所以,我计划使用这段代码.
let item0: UITabBarItem = UITabBarController().tabBar.items[0] as UITabBarItem
item0.setFinishedSelectedImage(selectedImage0, withFinishedUnselectedImage: unselectedImage0)
Run Code Online (Sandbox Code Playgroud)
但是,问题是setFinishedSelectedImage不再支持,我看到了这个错误.我该如何实施?
从iOS 7及更早版本开始不推荐使用的API在Swift中不可用
ios ×2
objective-c ×2
swift ×2
cocoa ×1
ios8 ×1
macos ×1
nsview ×1
object ×1
types ×1
uistoryboard ×1
uitableview ×1
vim ×1
xcode ×1
xcode5 ×1