UITableViewCell我使用以下代码在 a 上绘制一条水平线和一条垂直线,它在 iOS7 上运行良好。它在 Objective-C 中。
在 的子类中,
@property (strong, nonatomic) NSMutableArray *columns;
- (void)drawRect:(CGRect)rect
{
// In iOS7, you have to set the cell's background color to clear otherwise the drawing lines won't appear
self.backgroundColor = [UIColor clearColor];
// Drawing the vertical line
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(ctx, 0.5, 0.5, 0.5, 1.0);
CGContextSetLineWidth(ctx, 0.75);
for (int i = 0; i < self.columns.count; i++) {
CGFloat f = [((NSNumber*) [self.columns objectAtIndex:i]) floatValue];
CGContextMoveToPoint(ctx, f, 10);
CGContextAddLineToPoint(ctx, f, self.bounds.size.height …Run Code Online (Sandbox Code Playgroud) 这是这个问题的重复。因为我对 Swift 的了解都是 Swift3,所以我想知道是否有人可以“翻译”这个答案中建议的解决方案。
\n\n还:
\n\n我制作了一个没有边框的 NSSearchfield,将其放入框架视图中,它仍然显示灰色边框。我很好奇如何禁用动画灰色边框,甚至如何更改灰色“搜索”线的颜色。
\n\n我的丑陋结果现在看起来像这样:
\n\n\n\n如果有人能告诉我如何管理这个困难的 NSSearchfield,那将是一个很大的帮助。
\n\n//更新
\n\n根据firstinq\xc2\xb4s的回答,图标现在消失了,这很棒。但仍然存在令人不安的动画灰色边框。我可以\xc2\xb4t理解:NSSearchFielt位于NSView(蓝色边框)内。所以 NSView 之外的所有内容都应该隐藏,对吧?那么为什么我仍然看到灰色边框?cell.isBordered = false没有效果。\n有什么建议如何处理吗?
这就是我绘制 NSView 边框的方法:
\n\nclass SearchFieldBorder: NSView {\n\n override func draw(_ dirtyRect: NSRect) {\n super.draw(dirtyRect)\n\n self.layer?.borderWidth = 1\n self.layer?.borderColor = NSColor.blue.cgColor\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n 我有两个缓冲区,大小和类型都相同 ( uint32_t*)。这些缓冲区应该代表渲染/绘图系统的前缓冲区和后缓冲区。它们存储 32 位像素数据。
我使用以下方式声明并初始化这些缓冲区:
private:
...
uint32_t* frontBuf;
uint32_t* backBuf;
size_t gbufSize;
...
public:
void Initialize() {
...
// prepare for rendering
gbufSize = sizeof(uint32_t) * w * h;
backBuf = (uint32_t*)malloc(gbufSize);
frontBuf = (uint32_t*)malloc(gbufSize);
...
}
Run Code Online (Sandbox Code Playgroud)
我还使用以下方法获取控制台的输出、窗口和设备句柄Initialize():
// get handles
cwd = GetDC(GetConsoleWindow());
chd = GetStdHandle(STD_OUTPUT_HANDLE);
cwn = GetConsoleWindow();
Run Code Online (Sandbox Code Playgroud)
然后我有几个绘图方法,比如一个SetPixel方法:
size_t GFlatten(int x, int y) {
return y * h + x;
}
void GSetPixel(int x, int y, uint32_t color) {
backBuf[GFlatten(x, …Run Code Online (Sandbox Code Playgroud) 我想改变我画的按钮的填充(我将NSButton子类化)
这是我已经得到的代码:
- (void)drawRect:(NSRect)dirtyRect {
// Drawing code here.
// Create the Gradient
NSGradient *fillGradient = [[NSGradient alloc] initWithStartingColor:[NSColor lightGrayColor] endingColor:[NSColor darkGrayColor]];
// Create the path
aPath = [NSBezierPath bezierPath];
[aPath moveToPoint:NSMakePoint(10.0, 0.0)];
[aPath lineToPoint:NSMakePoint(85.0, 0.0)];
[aPath lineToPoint:NSMakePoint(85.0, 20.0)];
[aPath lineToPoint:NSMakePoint(10.0, 20.0)];
[aPath lineToPoint:NSMakePoint(0.0, 10.0)];
[aPath lineToPoint:NSMakePoint(10.0, 0.0)];
[fillGradient drawInBezierPath:aPath angle:90.0];
[fillGradient release];
}
- (void)mouseDown:(NSEvent *)theEvent {
NSGradient *fillGradient = [[NSGradient alloc] initWithStartingColor:[NSColor lightGrayColor] endingColor:[NSColor darkGrayColor]];
[fillGradient drawInBezierPath:aPath angle:-90.0];
}
Run Code Online (Sandbox Code Playgroud)
我收到一个EXC_BAD_ACCESS信号 我该怎么做?
我想制作一个应用程序,我需要一个工具栏.工具栏将具有各种数量的对象(图像).这些对象应该是可拖动的,并放置在它正上方的视图上.
这是一种绘图应用程序,用户可以在画布上选择任何形状和位置.谁能告诉我最好的方法呢?
提前致谢.
我正在使用silverlight 3.0进行申请.在那个应用程序中,我有一个公共方法
public void DrawWavform()
{
Line[,] line = new Line[10,200];
line[i,j]= new Line();//i am getting error here of invalid thread access
//some operation
}
Run Code Online (Sandbox Code Playgroud)
在应用程序中,我根据用户输入创建不同的线程,并从新创建的线程调用DrawWaveform方法.我想并行操作.请建议我解决.谢谢提前.
我正在将Skycons移植到Android上,我的大部分工作都在工作,除了月亮使用Canvas.arc带有逆时针参数的HTML5 .
我试图这样实现:
RectF rect = new RectF();
public void arcR( Path path, float x, float y, float radius, double startAngle, double endAngle, boolean anticlockwise ){
// Set bounds
rect.set( x - radius, y - radius, x + radius, y + radius );
// Convert to degrees
startAngle = Math.toDegrees(startAngle);
endAngle = Math.toDegrees(endAngle);
if(anticlockwise){
startAngle = 360 - startAngle;
endAngle = 360 - endAngle;
}
endAngle = endAngle - startAngle;
path.addArc(rect, (float)startAngle, (float)endAngle);
}
Run Code Online (Sandbox Code Playgroud)
我认为我没有正确实施逆时针,因为在我的设备上绘制月球(基于Skycons)看起来像这样:
我使用gluPerspective主要增加绘制距离,但它似乎不起作用.
这是它在我的代码中显示的方式:
gluPerspective(0, 70/70, 0, 4333);
Run Code Online (Sandbox Code Playgroud)
ratio:窗口Width和Height都是700,它们是常数,如果想知道的话.
fovy:我把0,因为,"他们"说使用45是非常好画,但它停止在屏幕上绘图.
这是完整的代码:
#include <Windows.h>
#include <gl\GL.h>
#include <gl/glut.h>
WNDCLASSEX wclass;
MSG msg;
HWND hwnd;
HDC hdc;
HDC p_hdc;
float t;
int red, green, blue, x, y, z;
void update()
{
RECT rec;
GetClientRect(hwnd, &rec);
InvalidateRect(hwnd, &rec, false);
UpdateWindow(hwnd);
t += 0.5f;
}
void game()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0, 0, 0, 0);
float norm = 1;
float z = 0;
red = 255;
green = 255;
glPushMatrix();
glRotatef(t, 0, 1, 1);
glBegin(GL_TRIANGLES);
glColor3f(255, …Run Code Online (Sandbox Code Playgroud)