2013-11-26 22 views
7

iOS7通知センターでは、ラベル(およびセパレータライン)には非常に興味深い背景があります:ぼかし画像と、ソフトライトブレンドモードのようなものです。iOS 7通知センターのようなラベル

私は何を検索するのか不明です。これがどうやってできるかについての指針は本当に高く評価されます。

これまで、label.textColor = [UIColor colorWithPatternImage:...]を使用して、ぼやけた画像の一部を背景として設定して、効果を再現しようとしました。これは、背景がすべて黒(または白)で、テキストが判読不能になる場合も考慮しません。

しかし、それはちょうどうまく動作しないようです。このよう

Blur example

は、ここで私が試したものです:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    const CGFloat fontSize = 25.f; 
    const NSString *text = @"A long-ish string"; 
    CGSize size = [text sizeWithAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"Avenir Next" size:fontSize]}]; 
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(80, 270, size.width, size.height)]; 
    label.font = [UIFont fontWithName:@"Avenir Next" size:fontSize]; 
    label.textAlignment = NSTextAlignmentNatural; 
    label.backgroundColor = [UIColor clearColor]; 
    label.text = text; 

    UIImage *image = [UIImage imageNamed:@"[email protected]"]; 
    UIImage *blurredImage = [image applyBlurWithRadius:20.5 tintColor:[UIColor clearColor] saturationDeltaFactor:1.f maskImage:nil]; 

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[blurredImage applyDarkEffect]]; 
    imageView.frame = self.view.bounds; 

    CGFloat imgScale = image.scale; 
    CGRect labelFrame = label.frame; 
    CGRect realRect = CGRectMake(labelFrame.origin.x * imgScale, labelFrame.origin.y * imgScale, labelFrame.size.width * imgScale, labelFrame.size.height * 2.0); 
    CGImageRef labelPatternImage = CGImageCreateWithImageInRect(image.CGImage, realRect); 
    label.textColor = [UIColor colorWithPatternImage:[UIImage imageWithCGImage:labelPatternImage scale:2.f orientation:UIImageOrientationUp]]; 
    CGImageRelease(labelPatternImage); 

    [self.view addSubview:imageView]; 
    [self.view addSubview:label]; 
} 

Code Result http://caughtinflux.com/static/result.png
でこのコードの結果はご覧のように、それは類似していませんNCラベル。

EDIT
できるだけ実際の背景と整列べきテキストのボケ画像の背景。うまくいけば、私のコードのシミュレータのスクリーンショットは、私が言っていることを理解するのに役立ちます。

答えて

1

まだラベルのアルファ値を調整してみましたか? これを試して、ラベルに適用する前にぼかしに少しの白を加えることができます。

+0

あなたの2番目のコメントが掲載されました!私はぼかしの前に画像にわずかな白い色合いを付け加えました。それは私が複製しようとしているものにかなり近いものでした。ラベルのtextColorとしてぼかしを設定すると、上のコードのようにうまく動作します。ありがとう!私のコードではイメージを使用していますが、Gregの答えは、iOSで新しいスナップショットAPIを使用して同じものを作成する方法も示しています。 – caughtinflux

+0

スクロールはどうですか? @caughtinflux –

+0

スクロールビューのcontentOffsetに基づいて画像を調整し続ける必要があります – caughtinflux

2

これはぼかし効果です。アップルのカテゴリはUIImageにあり、この効果はavailable for download hereです。言うができますとあなたはその上にラベルを使用してビューを作成することができます

UIImage *backgImage = [image applyBlurWithRadius:2 
tintColor:tintColor saturationDeltaFactor:0.8 maskImage:nil]; 

//拡張

:ファイル名は、任意のあなたがそのようにそれを使用することができますUIImage + ImageEffects.h/UIImage + ImageEffects.mです白いテキストの色(全体をぼかして表示するときにハイライト表示)した後、このビューのスナップショットを作成し、使用できるビューの背景として設定することができます([self.view setBackgroundColor:[UIColor colorWithPatternImage:blurredImage];)。

  UIView *snapshotView = [YOURUIVIEW resizableSnapshotViewFromRect:self.contentView.frame afterScreenUpdates:YES withCapInsets:UIEdgeInsetsZero]; 

      UIGraphicsBeginImageContextWithOptions(self.contentView.bounds.size, YES, 0.0f); 
      BOOL result = [snapshotView drawViewHierarchyInRect:self.contentView.bounds 
      afterScreenUpdates:YES]; 
      UIImage *snapshotImage = 
      UIGraphicsGetImageFromCurrentImageContext(); 
      UIGraphicsEndImageContext(); 
      if (result){ 
       UIColor *tintColor = [UIColor colorWithWhite:0.97 alpha:0.82]; 
       UIImage *blurredImage = [snapshotImage applyBlurWithRadius:4 tintColor:tintColor saturationDeltaFactor:1.8 
       maskImage:nil]; 
      } 

あなたに必要なものがあるかどうか教えてください。それができない場合は、詳細を説明して、何を達成したいのですか?

+0

これは、そのファイルへの[リンク](https://developer.apple.com/downloads/download.action?path=wwdc_2013/wwdc_2013_sample_code/ios_uiimageeffects.zip)です。 – Greg

+0

私も同じカテゴリを使用していますが、これは実際に私の質問に答えるものではありません。 – caughtinflux

+0

これは私が作業していたコード(編集を参照)と似ていますが、実際の背景にテキストカラーとして使用されているパターンイメージを整列させようとはしません。 – caughtinflux

1

私はセパレータ、選択した背景の景色と(今日のように)ラベルのような通知センターとサンプルプロジェクトを持っています。 https://github.com/mikrohard/BluredTableView

はまだいくつかのバグなど、もパフォーマンスの問題があるかもしれません。しかし使用して、それを改善して自由に感じる:

あなたはここでそれを見てすることができます。

+0

オフトピックの自己広告...? – holex

+0

ライブラリはこの効果を実装しません。彼はAppleのUIImage + Effectsを使用しています – bcattle

関連する問題