SORU
13 Aralık 2010, PAZARTESİ


Gölge UİView katman üzerinde etkisi iç?

Aşağıdaki CALayer var:

CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = CGRectMake(8, 57, 296, 30);
gradient.cornerRadius = 3.0f;
gradient.colors = [NSArray arrayWithObjects:(id)[RGB(130, 0, 140) CGColor], (id)[RGB(108, 0, 120) CGColor], nil];
[self.layer insertSublayer:gradient atIndex:0];

Bir ekleme yapmak istiyorumİç Gölgebu etki, ama bunu nasıl emin değilim. Sanırım ki olması gereken berabere drawRect, ancak bu Ekle katmanının üstüne diğer UİView nesneleri beri olması gerektiği bir bar arkasında bir düğme, bu yüzden ben bir kayıp olarak ne için?

Başka bir katman, ama yine, İç Gölge efekti elde etmek için nasıl (bu gibi: . emin ekleyebilirim

enter image description here

Takdir yardım...

CEVAP
4 NİSAN 2011, PAZARTESİ


Costique önerisine göre herkesten bir İç Gölge Çekirdekli Grafik kullanarak çizmek ne kadar merak, o zaman bu nasıl: (iOS gerektiği gibi ayarlayın)

Senin drawRect: yöntem...

CGRect bounds = [self bounds];
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat radius = 0.5f * CGRectGetHeight(bounds);


// Create the "visible" path, which will be the shape that gets the inner shadow
// In this case it's just a rounded rect, but could be as complex as your want
CGMutablePathRef visiblePath = CGPathCreateMutable();
CGRect innerRect = CGRectInset(bounds, radius, radius);
CGPathMoveToPoint(visiblePath, NULL, innerRect.origin.x, bounds.origin.y);
CGPathAddLineToPoint(visiblePath, NULL, innerRect.origin.x   innerRect.size.width, bounds.origin.y);
CGPathAddArcToPoint(visiblePath, NULL, bounds.origin.x   bounds.size.width, bounds.origin.y, bounds.origin.x   bounds.size.width, innerRect.origin.y, radius);
CGPathAddLineToPoint(visiblePath, NULL, bounds.origin.x   bounds.size.width, innerRect.origin.y   innerRect.size.height);
CGPathAddArcToPoint(visiblePath, NULL,  bounds.origin.x   bounds.size.width, bounds.origin.y   bounds.size.height, innerRect.origin.x   innerRect.size.width, bounds.origin.y   bounds.size.height, radius);
CGPathAddLineToPoint(visiblePath, NULL, innerRect.origin.x, bounds.origin.y   bounds.size.height);
CGPathAddArcToPoint(visiblePath, NULL,  bounds.origin.x, bounds.origin.y   bounds.size.height, bounds.origin.x, innerRect.origin.y   innerRect.size.height, radius);
CGPathAddLineToPoint(visiblePath, NULL, bounds.origin.x, innerRect.origin.y);
CGPathAddArcToPoint(visiblePath, NULL,  bounds.origin.x, bounds.origin.y, innerRect.origin.x, bounds.origin.y, radius);
CGPathCloseSubpath(visiblePath);

// Fill this path
UIColor *aColor = [UIColor redColor];
[aColor setFill];
CGContextAddPath(context, visiblePath);
CGContextFillPath(context);


// Now create a larger rectangle, which we're going to subtract the visible path from
// and apply a shadow
CGMutablePathRef path = CGPathCreateMutable();
//(when drawing the shadow for a path whichs bounding box is not known pass "CGPathGetPathBoundingBox(visiblePath)" instead of "bounds" in the following line:)
//-42 cuould just be any offset > 0
CGPathAddRect(path, NULL, CGRectInset(bounds, -42, -42));

// Add the visible path (so that it gets subtracted for the shadow)
CGPathAddPath(path, NULL, visiblePath);
CGPathCloseSubpath(path);

// Add the visible paths as the clipping path to the context
CGContextAddPath(context, visiblePath); 
CGContextClip(context);         


// Now setup the shadow properties on the context
aColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.5f];
CGContextSaveGState(context);
CGContextSetShadowWithColor(context, CGSizeMake(0.0f, 1.0f), 3.0f, [aColor CGColor]);   

// Now fill the rectangle, so the shadow gets drawn
[aColor setFill];   
CGContextSaveGState(context);   
CGContextAddPath(context, path);
CGContextEOFillPath(context);

// Release the paths
CGPathRelease(path);    
CGPathRelease(visiblePath);

Yani, temel olarak şu adımları vardır:

  1. Kendi yolunu oluşturmak
  2. Dolgu istediğiniz rengi ayarlamak, içerik için bu yolu ekleyin ve içeriği doldurmak
  3. Şimdi görünür yoluna bağlı olan daha büyük bir dikdörtgen oluşturun. Kapatmadan önce bu yolu görünür yolunu ekleyin. O zaman yakın görünür yolu düşülen bir şekil oluşturmak, böylece yolu. Dolgu yöntemleri (sıfır çift/tek sarım) bu yollar seni nasıl yarattığını bağlı olarak araştırmak isteyebilirsiniz. Özünde, almak için alt yolları için "çıkart" eklediğinizde onlarla birlikte, onları çekmek (ya da daha doğrusu onları inşa etmek) zıt yönlerde, biri saat yönünde diğeri saat yönünün tersine.
  4. Daha sonra ekrana dışında herhangi bir şey çizmek değil ki bağlama kırpma yolu olarak görünür yolu ayarlamanız gerekir.
  5. O zaman ofset, bulanıklık ve renk içerir, hangi bağlamda gölge Kur.
  6. Sonra delik olan büyük şekli dolduracak. Renk eğer her şeyi doğru yaptıysan eğer, bu renk Göremezsiniz, çünkü önemli değil, sadece gölge.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Adam Washington

    Adam Washing

    12 Mayıs 2006
  • ChannelRichard

    ChannelRicha

    7 Kasım 2008
  • MrOctopi

    MrOctopi

    6 Aralık 2010